mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Ensure symbols work for _.assign, _.defaults, & _.merge.
This commit is contained in:
@@ -1777,8 +1777,10 @@
|
|||||||
* @returns {Object} Returns `object`.
|
* @returns {Object} Returns `object`.
|
||||||
*/
|
*/
|
||||||
function assignWith(object, source, customizer) {
|
function assignWith(object, source, customizer) {
|
||||||
|
var props = keys(source);
|
||||||
|
push.apply(props, getSymbols(source));
|
||||||
|
|
||||||
var index = -1,
|
var index = -1,
|
||||||
props = keys(source),
|
|
||||||
length = props.length;
|
length = props.length;
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
@@ -2573,22 +2575,32 @@
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
|
var isSrcArr = isLength(source.length) && (isArray(source) || isTypedArray(source));
|
||||||
(isSrcArr ? arrayEach : baseForOwn)(source, function(srcValue, key, source) {
|
if (!isSrcArr) {
|
||||||
|
var props = keys(source);
|
||||||
|
push.apply(props, getSymbols(source));
|
||||||
|
}
|
||||||
|
arrayEach(props || source, function(srcValue, key) {
|
||||||
|
if (props) {
|
||||||
|
key = srcValue;
|
||||||
|
srcValue = source[key];
|
||||||
|
}
|
||||||
if (isObjectLike(srcValue)) {
|
if (isObjectLike(srcValue)) {
|
||||||
stackA || (stackA = []);
|
stackA || (stackA = []);
|
||||||
stackB || (stackB = []);
|
stackB || (stackB = []);
|
||||||
return baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
|
baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
|
||||||
}
|
}
|
||||||
var value = object[key],
|
else {
|
||||||
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
|
var value = object[key],
|
||||||
isCommon = result === undefined;
|
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
|
||||||
|
isCommon = result === undefined;
|
||||||
|
|
||||||
if (isCommon) {
|
if (isCommon) {
|
||||||
result = srcValue;
|
result = srcValue;
|
||||||
}
|
}
|
||||||
if ((isSrcArr || result !== undefined) &&
|
if ((isSrcArr || result !== undefined) &&
|
||||||
(isCommon || (result === result ? (result !== value) : (value === value)))) {
|
(isCommon || (result === result ? (result !== value) : (value === value)))) {
|
||||||
object[key] = result;
|
object[key] = result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return object;
|
return object;
|
||||||
|
|||||||
21
test/test.js
21
test/test.js
@@ -5767,6 +5767,25 @@
|
|||||||
deepEqual(func({}, new Foo), { 'a': 1 });
|
deepEqual(func({}, new Foo), { 'a': 1 });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('`_.' + methodName + '` should assign own symbols', 2, function() {
|
||||||
|
if (Symbol) {
|
||||||
|
var symbol1 = Symbol('a'),
|
||||||
|
symbol2 = Symbol('b');
|
||||||
|
|
||||||
|
var Foo = function() {
|
||||||
|
this[symbol1] = 1;
|
||||||
|
};
|
||||||
|
Foo.prototype[symbol2] = 2;
|
||||||
|
|
||||||
|
var actual = func({}, new Foo);
|
||||||
|
strictEqual(actual[symbol1], 1);
|
||||||
|
strictEqual(actual[symbol2], undefined);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should assign problem JScript properties (test in IE < 9)', 1, function() {
|
test('`_.' + methodName + '` should assign problem JScript properties (test in IE < 9)', 1, function() {
|
||||||
var object = {
|
var object = {
|
||||||
'constructor': '0',
|
'constructor': '0',
|
||||||
@@ -5881,7 +5900,7 @@
|
|||||||
if (isMerge) {
|
if (isMerge) {
|
||||||
expected.push([undefined, 2, 'b', sourceValue, sourceValue]);
|
expected.push([undefined, 2, 'b', sourceValue, sourceValue]);
|
||||||
}
|
}
|
||||||
deepEqual(argsList, expected, 'non-primitive property values');
|
deepEqual(argsList, expected, 'object property values');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should support the `thisArg` argument', 1, function() {
|
test('`_.' + methodName + '` should support the `thisArg` argument', 1, function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user