Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid mutating options #173

Merged
merged 5 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})