diff --git a/changelog.md b/changelog.md index 29b038d..96dff46 100644 --- a/changelog.md +++ b/changelog.md @@ -1,8 +1,9 @@ # [5.0.0](https://github.com/TehShrike/deepmerge/releases/tag/v5.0.0) -- Breaking: Dropped ES5 support. [#161](https://github.com/TehShrike/deepmerge/issues/161) +- Breaking: The shipped bundle now targets ES2015 instead of ES5. If you target IE11, you'll need to change your build process to compile dependencies. [#161](https://github.com/TehShrike/deepmerge/issues/161) - Breaking: by default, only [plain objects](https://github.com/sindresorhus/is-plain-obj/#is-plain-obj-) will have their properties merged, with all other values being copied to the target. [#152](https://github.com/TehShrike/deepmerge/issues/152) - Breaking: the `isMergeableObject` option is renamed to `isMergeable` [#168](https://github.com/TehShrike/deepmerge/pull/168) +- Fixed: the options argument is no longer mutated (again) [#173](https://github.com/TehShrike/deepmerge/pull/173) # [4.2.2](https://github.com/TehShrike/deepmerge/releases/tag/v4.2.2) diff --git a/index.js b/index.js index bf65974..2600ec5 100644 --- a/index.js +++ b/index.js @@ -70,13 +70,15 @@ const mergeObject = (target, source, options) => { return destination } -const deepmerge = (target, source, options) => { - options = Object.assign({ +const deepmerge = (target, source, inputOptions) => { + const options = { arrayMerge: defaultArrayMerge, isMergeable: defaultIsMergeable, - }, options, { - cloneUnlessOtherwiseSpecified, - }) + ...inputOptions, + // cloneUnlessOtherwiseSpecified is added to `options` so that custom arrayMerge() + // implementations can use it. The caller may not replace it. + cloneUnlessOtherwiseSpecified: cloneUnlessOtherwiseSpecified + } const sourceIsArray = Array.isArray(source) const targetIsArray = Array.isArray(target) diff --git a/test/merge.js b/test/merge.js index 1a99b28..acf0fa6 100644 --- a/test/merge.js +++ b/test/merge.js @@ -676,3 +676,12 @@ test('Falsey properties should be mergeable', function(t) { t.ok(customMergeWasCalled, 'custom merge function was called') t.end() }) + +test('should not mutate options', function(t) { + var options = {} + + merge({}, {}, options) + + t.deepEqual(options, {}) + t.end() +})