|
@@ -2,10 +2,10 @@ import Stack from './_Stack';
|
|
|
import arrayEach from './_arrayEach';
|
|
import arrayEach from './_arrayEach';
|
|
|
import assignValue from './_assignValue';
|
|
import assignValue from './_assignValue';
|
|
|
import baseAssign from './_baseAssign';
|
|
import baseAssign from './_baseAssign';
|
|
|
-import baseForOwn from './_baseForOwn';
|
|
|
|
|
import cloneBuffer from './_cloneBuffer';
|
|
import cloneBuffer from './_cloneBuffer';
|
|
|
import copyArray from './_copyArray';
|
|
import copyArray from './_copyArray';
|
|
|
import copySymbols from './_copySymbols';
|
|
import copySymbols from './_copySymbols';
|
|
|
|
|
+import getAllKeys from './_getAllKeys';
|
|
|
import getTag from './_getTag';
|
|
import getTag from './_getTag';
|
|
|
import initCloneArray from './_initCloneArray';
|
|
import initCloneArray from './_initCloneArray';
|
|
|
import initCloneByTag from './_initCloneByTag';
|
|
import initCloneByTag from './_initCloneByTag';
|
|
@@ -14,6 +14,7 @@ import isArray from './isArray';
|
|
|
import isBuffer from './isBuffer';
|
|
import isBuffer from './isBuffer';
|
|
|
import isHostObject from './_isHostObject';
|
|
import isHostObject from './_isHostObject';
|
|
|
import isObject from './isObject';
|
|
import isObject from './isObject';
|
|
|
|
|
+import keys from './keys';
|
|
|
|
|
|
|
|
/** `Object#toString` result references. */
|
|
/** `Object#toString` result references. */
|
|
|
var argsTag = '[object Arguments]',
|
|
var argsTag = '[object Arguments]',
|
|
@@ -33,6 +34,7 @@ var argsTag = '[object Arguments]',
|
|
|
weakMapTag = '[object WeakMap]';
|
|
weakMapTag = '[object WeakMap]';
|
|
|
|
|
|
|
|
var arrayBufferTag = '[object ArrayBuffer]',
|
|
var arrayBufferTag = '[object ArrayBuffer]',
|
|
|
|
|
+ dataViewTag = '[object DataView]',
|
|
|
float32Tag = '[object Float32Array]',
|
|
float32Tag = '[object Float32Array]',
|
|
|
float64Tag = '[object Float64Array]',
|
|
float64Tag = '[object Float64Array]',
|
|
|
int8Tag = '[object Int8Array]',
|
|
int8Tag = '[object Int8Array]',
|
|
@@ -46,16 +48,16 @@ var arrayBufferTag = '[object ArrayBuffer]',
|
|
|
/** Used to identify `toStringTag` values supported by `_.clone`. */
|
|
/** Used to identify `toStringTag` values supported by `_.clone`. */
|
|
|
var cloneableTags = {};
|
|
var cloneableTags = {};
|
|
|
cloneableTags[argsTag] = cloneableTags[arrayTag] =
|
|
cloneableTags[argsTag] = cloneableTags[arrayTag] =
|
|
|
-cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
|
|
|
|
|
-cloneableTags[dateTag] = cloneableTags[float32Tag] =
|
|
|
|
|
-cloneableTags[float64Tag] = cloneableTags[int8Tag] =
|
|
|
|
|
-cloneableTags[int16Tag] = cloneableTags[int32Tag] =
|
|
|
|
|
-cloneableTags[mapTag] = cloneableTags[numberTag] =
|
|
|
|
|
-cloneableTags[objectTag] = cloneableTags[regexpTag] =
|
|
|
|
|
-cloneableTags[setTag] = cloneableTags[stringTag] =
|
|
|
|
|
-cloneableTags[symbolTag] = cloneableTags[uint8Tag] =
|
|
|
|
|
-cloneableTags[uint8ClampedTag] = cloneableTags[uint16Tag] =
|
|
|
|
|
-cloneableTags[uint32Tag] = true;
|
|
|
|
|
|
|
+cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
|
|
|
|
|
+cloneableTags[boolTag] = cloneableTags[dateTag] =
|
|
|
|
|
+cloneableTags[float32Tag] = cloneableTags[float64Tag] =
|
|
|
|
|
+cloneableTags[int8Tag] = cloneableTags[int16Tag] =
|
|
|
|
|
+cloneableTags[int32Tag] = cloneableTags[mapTag] =
|
|
|
|
|
+cloneableTags[numberTag] = cloneableTags[objectTag] =
|
|
|
|
|
+cloneableTags[regexpTag] = cloneableTags[setTag] =
|
|
|
|
|
+cloneableTags[stringTag] = cloneableTags[symbolTag] =
|
|
|
|
|
+cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
|
|
|
|
|
+cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
|
|
|
cloneableTags[errorTag] = cloneableTags[funcTag] =
|
|
cloneableTags[errorTag] = cloneableTags[funcTag] =
|
|
|
cloneableTags[weakMapTag] = false;
|
|
cloneableTags[weakMapTag] = false;
|
|
|
|
|
|
|
@@ -103,14 +105,13 @@ function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
|
|
|
}
|
|
}
|
|
|
result = initCloneObject(isFunc ? {} : value);
|
|
result = initCloneObject(isFunc ? {} : value);
|
|
|
if (!isDeep) {
|
|
if (!isDeep) {
|
|
|
- result = baseAssign(result, value);
|
|
|
|
|
- return isFull ? copySymbols(value, result) : result;
|
|
|
|
|
|
|
+ return copySymbols(value, baseAssign(result, value));
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
if (!cloneableTags[tag]) {
|
|
if (!cloneableTags[tag]) {
|
|
|
return object ? value : {};
|
|
return object ? value : {};
|
|
|
}
|
|
}
|
|
|
- result = initCloneByTag(value, tag, isDeep);
|
|
|
|
|
|
|
+ result = initCloneByTag(value, tag, baseClone, isDeep);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
// Check for circular references and return its corresponding clone.
|
|
// Check for circular references and return its corresponding clone.
|
|
@@ -121,11 +122,18 @@ function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
|
|
|
}
|
|
}
|
|
|
stack.set(value, result);
|
|
stack.set(value, result);
|
|
|
|
|
|
|
|
|
|
+ if (!isArr) {
|
|
|
|
|
+ var props = isFull ? getAllKeys(value) : keys(value);
|
|
|
|
|
+ }
|
|
|
// Recursively populate clone (susceptible to call stack limits).
|
|
// Recursively populate clone (susceptible to call stack limits).
|
|
|
- (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
|
|
|
|
|
|
|
+ arrayEach(props || value, function(subValue, key) {
|
|
|
|
|
+ if (props) {
|
|
|
|
|
+ key = subValue;
|
|
|
|
|
+ subValue = value[key];
|
|
|
|
|
+ }
|
|
|
assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
|
|
assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
|
|
|
});
|
|
});
|
|
|
- return (isFull && !isArr) ? copySymbols(value, result) : result;
|
|
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export default baseClone;
|
|
export default baseClone;
|