Skip to content

Commit

Permalink
Merge pull request #173 from ArtskydJ/no-mutate-opts
Browse files Browse the repository at this point in the history
  • Loading branch information
TehShrike authored Jan 20, 2021
2 parents 5fa97cb + 59402c1 commit caa79e2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions test/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

0 comments on commit caa79e2

Please sign in to comment.