Fix inconsistent merging of multiple sources to function property

This commit is contained in:
sina
2018-06-21 00:54:05 +04:30
committed by John-David Dalton
parent 6e62e1e8df
commit 79b9d20a91
3 changed files with 24 additions and 5 deletions

1
.gitignore vendored
View File

@@ -2,3 +2,4 @@
*.log *.log
doc/*.html doc/*.html
node_modules node_modules
.idea

View File

@@ -3681,7 +3681,7 @@
if (isArguments(objValue)) { if (isArguments(objValue)) {
newValue = toPlainObject(objValue); newValue = toPlainObject(objValue);
} }
else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) { else if (!isObject(objValue) || isFunction(objValue)) {
newValue = initCloneObject(srcValue); newValue = initCloneObject(srcValue);
} }
} }

View File

@@ -14830,7 +14830,7 @@
}()); }());
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
// sina
QUnit.module('lodash.merge'); QUnit.module('lodash.merge');
(function() { (function() {
@@ -14911,8 +14911,28 @@
assert.strictEqual(Foo.a, 1); assert.strictEqual(Foo.a, 1);
}); });
QUnit.test('should merge first source object properties to function', function(assert) {
assert.expect(1);
const Foo = function () {};
var object = { prop: {} },
actual = _.merge({prop: Foo}, object);
assert.deepEqual(actual, object);
});
QUnit.test('should merge first and second source object properties to function', function(assert) {
assert.expect(1);
const fn = function () {};
var object = { prop: {} },
actual = _.merge({prop: fn}, {prop: fn}, object);
assert.deepEqual(actual, object);
});
QUnit.test('should not merge onto function values of sources', function(assert) { QUnit.test('should not merge onto function values of sources', function(assert) {
assert.expect(3); assert.expect(2);
var source1 = { 'a': function() {} }, var source1 = { 'a': function() {} },
source2 = { 'a': { 'b': 2 } }, source2 = { 'a': { 'b': 2 } },
@@ -14921,8 +14941,6 @@
assert.deepEqual(actual, { 'a': { 'b': 2 } }); assert.deepEqual(actual, { 'a': { 'b': 2 } });
actual = _.merge(source1, source2); actual = _.merge(source1, source2);
assert.strictEqual(typeof actual.a, 'function');
assert.strictEqual(actual.a.b, 2); assert.strictEqual(actual.a.b, 2);
}); });