mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 20:07:49 +00:00
Only copy symbols on objects and nested objects.
This commit is contained in:
17
lodash.js
17
lodash.js
@@ -2237,7 +2237,7 @@
|
|||||||
if (isArr) {
|
if (isArr) {
|
||||||
result = initCloneArray(value);
|
result = initCloneArray(value);
|
||||||
if (!isDeep) {
|
if (!isDeep) {
|
||||||
result = copyArray(value, result);
|
return copyArray(value, result);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var tag = getTag(value),
|
var tag = getTag(value),
|
||||||
@@ -2249,17 +2249,14 @@
|
|||||||
}
|
}
|
||||||
result = initCloneObject(isFunc ? {} : value);
|
result = initCloneObject(isFunc ? {} : value);
|
||||||
if (!isDeep) {
|
if (!isDeep) {
|
||||||
result = baseAssign(result, value);
|
return assignSymbols(baseAssign(result, value), value);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else if (!cloneableTags[tag]) {
|
return cloneableTags[tag]
|
||||||
return object ? value : {};
|
? initCloneByTag(value, tag, isDeep)
|
||||||
}
|
: (object ? value : {});
|
||||||
else {
|
|
||||||
result = initCloneByTag(value, tag, isDeep);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = assignSymbols(result, value);
|
|
||||||
if (!isDeep) {
|
if (!isDeep) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -2275,7 +2272,7 @@
|
|||||||
(isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
|
(isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
|
||||||
assignValue(result, key, baseClone(subValue, isDeep, customizer, key, value, stack));
|
assignValue(result, key, baseClone(subValue, isDeep, customizer, key, value, stack));
|
||||||
});
|
});
|
||||||
return result;
|
return isArr ? result : assignSymbols(result, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
20
test/test.js
20
test/test.js
@@ -2382,18 +2382,24 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test('`_.' + methodName + '` should clone symbol properties', function(assert) {
|
QUnit.test('`_.' + methodName + '` should clone symbol properties', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(2);
|
||||||
|
|
||||||
if (Symbol) {
|
if (Symbol) {
|
||||||
var values = [[], Object(false), new Date, {}, Object(0), /a/, Object('a')];
|
var object = {};
|
||||||
|
object[symbol] = {};
|
||||||
|
assert.strictEqual(func(object)[symbol], object[symbol]);
|
||||||
|
|
||||||
assert.ok(lodashStable.every(values, function(value) {
|
if (isDeep) {
|
||||||
value[symbol] = {};
|
object = { 'a': { 'b': {} } };
|
||||||
return func(value)[symbol] === value[symbol];
|
object.a.b[symbol] = {};
|
||||||
}));
|
assert.strictEqual(func(object).a.b[symbol], object.a.b[symbol]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
skipTest(assert);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
skipTest(assert);
|
skipTest(assert, 2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user