mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
mergeWith: stack passed to customizer should always be defined (#4244)
Summary: If the first values encountered in the `object` in mergeWith are not objects, `stack` is undefined when passed to the `customizer`. Once the first object-ish value is encountered, `stack` gets initialized, and all further calls to `customizer` include a defined `stack`. This PR makes `stack` always defined, even before the first object-ish value is encountered.
This commit is contained in:
committed by
John-David Dalton
parent
7084300d34
commit
0b8592a35c
@@ -3588,8 +3588,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
baseFor(source, function(srcValue, key) {
|
baseFor(source, function(srcValue, key) {
|
||||||
|
stack || (stack = new Stack);
|
||||||
if (isObject(srcValue)) {
|
if (isObject(srcValue)) {
|
||||||
stack || (stack = new Stack);
|
|
||||||
baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
|
baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
19
test/test.js
19
test/test.js
@@ -15280,18 +15280,21 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should provide `stack` to `customizer`', function(assert) {
|
QUnit.test('should provide `stack` to `customizer`', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(4);
|
||||||
|
|
||||||
var actual;
|
var actual = [];
|
||||||
|
|
||||||
_.mergeWith({}, { 'a': { 'b': 2 } }, function() {
|
_.mergeWith({}, { 'z': 1, 'a': { 'b': 2 } }, function() {
|
||||||
actual = _.last(arguments);
|
actual.push(_.last(arguments));
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.ok(isNpm
|
assert.strictEqual(actual.length, 3);
|
||||||
? actual.constructor.name == 'Stack'
|
_.each(actual, function(a) {
|
||||||
: actual instanceof mapCaches.Stack
|
assert.ok(isNpm
|
||||||
);
|
? a.constructor.name == 'Stack'
|
||||||
|
: a instanceof mapCaches.Stack
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('should overwrite primitives with source object clones', function(assert) {
|
QUnit.test('should overwrite primitives with source object clones', function(assert) {
|
||||||
|
|||||||
Reference in New Issue
Block a user