|
|
@@ -1,17 +1,19 @@
|
|
|
-import Stack from './Stack';
|
|
|
-import arrayEach from './arrayEach';
|
|
|
-import assignValue from './assignValue';
|
|
|
-import baseAssign from './baseAssign';
|
|
|
-import baseForOwn from './baseForOwn';
|
|
|
-import copyArray from './copyArray';
|
|
|
-import copySymbols from './copySymbols';
|
|
|
-import getTag from './getTag';
|
|
|
-import initCloneArray from './initCloneArray';
|
|
|
-import initCloneByTag from './initCloneByTag';
|
|
|
-import initCloneObject from './initCloneObject';
|
|
|
-import isArray from '../isArray';
|
|
|
-import isHostObject from './isHostObject';
|
|
|
-import isObject from '../isObject';
|
|
|
+import Stack from './_Stack';
|
|
|
+import arrayEach from './_arrayEach';
|
|
|
+import assignValue from './_assignValue';
|
|
|
+import baseAssign from './_baseAssign';
|
|
|
+import baseForOwn from './_baseForOwn';
|
|
|
+import cloneBuffer from './_cloneBuffer';
|
|
|
+import copyArray from './_copyArray';
|
|
|
+import copySymbols from './_copySymbols';
|
|
|
+import getTag from './_getTag';
|
|
|
+import initCloneArray from './_initCloneArray';
|
|
|
+import initCloneByTag from './_initCloneByTag';
|
|
|
+import initCloneObject from './_initCloneObject';
|
|
|
+import isArray from './isArray';
|
|
|
+import isBuffer from './isBuffer';
|
|
|
+import isHostObject from './_isHostObject';
|
|
|
+import isObject from './isObject';
|
|
|
|
|
|
/** `Object#toString` result references. */
|
|
|
var argsTag = '[object Arguments]',
|
|
|
@@ -64,13 +66,14 @@ cloneableTags[weakMapTag] = false;
|
|
|
* @private
|
|
|
* @param {*} value The value to clone.
|
|
|
* @param {boolean} [isDeep] Specify a deep clone.
|
|
|
+ * @param {boolean} [isFull] Specify a clone including symbols.
|
|
|
* @param {Function} [customizer] The function to customize cloning.
|
|
|
* @param {string} [key] The key of `value`.
|
|
|
* @param {Object} [object] The parent object of `value`.
|
|
|
* @param {Object} [stack] Tracks traversed objects and their clone counterparts.
|
|
|
* @returns {*} Returns the cloned value.
|
|
|
*/
|
|
|
-function baseClone(value, isDeep, customizer, key, object, stack) {
|
|
|
+function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
|
|
|
var result;
|
|
|
if (customizer) {
|
|
|
result = object ? customizer(value, key, object, stack) : customizer(value);
|
|
|
@@ -91,18 +94,23 @@ function baseClone(value, isDeep, customizer, key, object, stack) {
|
|
|
var tag = getTag(value),
|
|
|
isFunc = tag == funcTag || tag == genTag;
|
|
|
|
|
|
+ if (isBuffer(value)) {
|
|
|
+ return cloneBuffer(value, isDeep);
|
|
|
+ }
|
|
|
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
|
|
if (isHostObject(value)) {
|
|
|
return object ? value : {};
|
|
|
}
|
|
|
result = initCloneObject(isFunc ? {} : value);
|
|
|
if (!isDeep) {
|
|
|
- return copySymbols(value, baseAssign(result, value));
|
|
|
+ result = baseAssign(result, value);
|
|
|
+ return isFull ? copySymbols(value, result) : result;
|
|
|
}
|
|
|
} else {
|
|
|
- return cloneableTags[tag]
|
|
|
- ? initCloneByTag(value, tag, isDeep)
|
|
|
- : (object ? value : {});
|
|
|
+ if (!cloneableTags[tag]) {
|
|
|
+ return object ? value : {};
|
|
|
+ }
|
|
|
+ result = initCloneByTag(value, tag, isDeep);
|
|
|
}
|
|
|
}
|
|
|
// Check for circular references and return its corresponding clone.
|
|
|
@@ -115,9 +123,9 @@ function baseClone(value, isDeep, customizer, key, object, stack) {
|
|
|
|
|
|
// Recursively populate clone (susceptible to call stack limits).
|
|
|
(isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
|
|
|
- assignValue(result, key, baseClone(subValue, isDeep, customizer, key, value, stack));
|
|
|
+ assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
|
|
|
});
|
|
|
- return isArr ? result : copySymbols(value, result);
|
|
|
+ return (isFull && !isArr) ? copySymbols(value, result) : result;
|
|
|
}
|
|
|
|
|
|
export default baseClone;
|