1 var arrayCopy = require('./arrayCopy'),
2 isArguments = require('../lang/isArguments'),
3 isArray = require('../lang/isArray'),
4 isArrayLike = require('./isArrayLike'),
5 isPlainObject = require('../lang/isPlainObject'),
6 isTypedArray = require('../lang/isTypedArray'),
7 toPlainObject = require('../lang/toPlainObject');
10 * A specialized version of `baseMerge` for arrays and objects which performs
11 * deep merges and tracks traversed objects enabling objects with circular
12 * references to be merged.
15 * @param {Object} object The destination object.
16 * @param {Object} source The source object.
17 * @param {string} key The key of the value to merge.
18 * @param {Function} mergeFunc The function to merge values.
19 * @param {Function} [customizer] The function to customize merged values.
20 * @param {Array} [stackA=[]] Tracks traversed source objects.
21 * @param {Array} [stackB=[]] Associates values with source counterparts.
22 * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
24 function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
25 var length = stackA.length,
26 srcValue = source[key];
29 if (stackA[length] == srcValue) {
30 object[key] = stackB[length];
34 var value = object[key],
35 result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
36 isCommon = result === undefined;
40 if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
41 result = isArray(value)
43 : (isArrayLike(value) ? arrayCopy(value) : []);
45 else if (isPlainObject(srcValue) || isArguments(srcValue)) {
46 result = isArguments(value)
47 ? toPlainObject(value)
48 : (isPlainObject(value) ? value : {});
54 // Add the source value to the stack of traversed objects and associate
55 // it with its merged value.
56 stackA.push(srcValue);
60 // Recursively merge objects and arrays (susceptible to call stack limits).
61 object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
62 } else if (result === result ? (result !== value) : (value === value)) {
67 module.exports = baseMergeDeep;