From 2a23592c21dafc1ece673700db077fcd61e06200 Mon Sep 17 00:00:00 2001 From: Josh Duff Date: Mon, 21 Oct 2019 09:59:57 -0500 Subject: [PATCH] Revert "Manually rolling back #167" This reverts commit 55067352a92c65a6c44a5165f3387720aae1e192. --- index.js | 12 ++++++------ test/merge.js | 9 +++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index f0baf14..e3135d2 100644 --- a/index.js +++ b/index.js @@ -54,12 +54,12 @@ function mergeObject(target, source, options) { } function deepmerge(target, source, options) { - options = options || {} - options.arrayMerge = options.arrayMerge || defaultArrayMerge - options.isMergeableObject = options.isMergeableObject || defaultIsMergeableObject - // cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge() - // implementations can use it. The caller may not replace it. - options.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified + options = Object.assign({ + arrayMerge: defaultArrayMerge, + isMergeableObject: defaultIsMergeableObject + }, options, { + cloneUnlessOtherwiseSpecified: cloneUnlessOtherwiseSpecified + }) var sourceIsArray = Array.isArray(source) var targetIsArray = Array.isArray(target) diff --git a/test/merge.js b/test/merge.js index 44eca9f..f243422 100644 --- a/test/merge.js +++ b/test/merge.js @@ -637,3 +637,12 @@ test('copy symbol keys in target that do exist on the target', function(t) { t.equal(res[mySymbol], 'value1') t.end() }) + +test('should not mutate options', function(t) { + var options = {}; + + merge({}, {}, options); + + t.deepEqual(options, {}); + t.end(); +})