* A specialized version of `baseMerge` for arrays and objects which performs * deep merges and tracks traversed objects enabling objects with circular * references to be merged. * * @private * @param {Object} object The destination object. * @param {Object} source The source object. *
(object, source, key, srcIndex, mergeFunc, customizer, stack)
| 51803 | * counterparts. |
| 51804 | */ |
| 51805 | function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { |
| 51806 | var objValue = object[key], |
| 51807 | srcValue = source[key], |
| 51808 | stacked = stack.get(srcValue); |
| 51809 | |
| 51810 | if (stacked) { |
| 51811 | assignMergeValue(object, key, stacked); |
| 51812 | return; |
| 51813 | } |
| 51814 | var newValue = customizer ? customizer(objValue, srcValue, key + '', object, source, stack) : undefined; |
| 51815 | |
| 51816 | var isCommon = newValue === undefined; |
| 51817 | |
| 51818 | if (isCommon) { |
| 51819 | var isArr = isArray(srcValue), |
| 51820 | isBuff = !isArr && isBuffer(srcValue), |
| 51821 | isTyped = !isArr && !isBuff && isTypedArray(srcValue); |
| 51822 | |
| 51823 | newValue = srcValue; |
| 51824 | if (isArr || isBuff || isTyped) { |
| 51825 | if (isArray(objValue)) { |
| 51826 | newValue = objValue; |
| 51827 | } else if (isArrayLikeObject(objValue)) { |
| 51828 | newValue = copyArray(objValue); |
| 51829 | } else if (isBuff) { |
| 51830 | isCommon = false; |
| 51831 | newValue = cloneBuffer(srcValue, true); |
| 51832 | } else if (isTyped) { |
| 51833 | isCommon = false; |
| 51834 | newValue = cloneTypedArray(srcValue, true); |
| 51835 | } else { |
| 51836 | newValue = []; |
| 51837 | } |
| 51838 | } else if (isPlainObject(srcValue) || isArguments(srcValue)) { |
| 51839 | newValue = objValue; |
| 51840 | if (isArguments(objValue)) { |
| 51841 | newValue = toPlainObject(objValue); |
| 51842 | } else if (!isObject(objValue) || srcIndex && isFunction(objValue)) { |
| 51843 | newValue = initCloneObject(srcValue); |
| 51844 | } |
| 51845 | } else { |
| 51846 | isCommon = false; |
| 51847 | } |
| 51848 | } |
| 51849 | if (isCommon) { |
| 51850 | // Recursively merge objects and arrays (susceptible to call stack limits). |
| 51851 | stack.set(srcValue, newValue); |
| 51852 | mergeFunc(newValue, srcValue, srcIndex, customizer, stack); |
| 51853 | stack['delete'](srcValue); |
| 51854 | } |
| 51855 | assignMergeValue(object, key, newValue); |
| 51856 | } |
| 51857 | |
| 51858 | module.exports = baseMergeDeep; |
| 51859 |
no test coverage detected