mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
Update ESLint to 2.1.0. ESLint has a number of potentially-useful new features but this change attempts to be minimal in its changes. However, some things could not be avoided reasonably. ESLint 2.1.0 found a few lint issues that ESLing 1.x missed with template strings that did not take advantage of any features of template strings, and `let` declarations where `const` sufficed. Additionally, ESLint 2.1.0 removes some granularity around enabling ES6 features. Some features (e.g., spread operator) that had been turned off in our configuration for ESLint 1.x are now permitted. PR-URL: https://github.com/nodejs/node/pull/5214 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: jbergstroem - Johan Bergström <bugs@bergstroem.nu> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Myles Borins <myles.borins@gmail.com>
79 lines
2.6 KiB
JavaScript
79 lines
2.6 KiB
JavaScript
var assignMergeValue = require('./_assignMergeValue'),
|
|
baseClone = require('./_baseClone'),
|
|
copyArray = require('./_copyArray'),
|
|
isArguments = require('./isArguments'),
|
|
isArray = require('./isArray'),
|
|
isArrayLikeObject = require('./isArrayLikeObject'),
|
|
isFunction = require('./isFunction'),
|
|
isObject = require('./isObject'),
|
|
isPlainObject = require('./isPlainObject'),
|
|
isTypedArray = require('./isTypedArray'),
|
|
toPlainObject = require('./toPlainObject');
|
|
|
|
/**
|
|
* 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.
|
|
* @param {string} key The key of the value to merge.
|
|
* @param {number} srcIndex The index of `source`.
|
|
* @param {Function} mergeFunc The function to merge values.
|
|
* @param {Function} [customizer] The function to customize assigned values.
|
|
* @param {Object} [stack] Tracks traversed source values and their merged counterparts.
|
|
*/
|
|
function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
|
|
var objValue = object[key],
|
|
srcValue = source[key],
|
|
stacked = stack.get(srcValue);
|
|
|
|
if (stacked) {
|
|
assignMergeValue(object, key, stacked);
|
|
return;
|
|
}
|
|
var newValue = customizer ? customizer(objValue, srcValue, (key + ''), object, source, stack) : undefined,
|
|
isCommon = newValue === undefined;
|
|
|
|
if (isCommon) {
|
|
newValue = srcValue;
|
|
if (isArray(srcValue) || isTypedArray(srcValue)) {
|
|
if (isArray(objValue)) {
|
|
newValue = srcIndex ? copyArray(objValue) : objValue;
|
|
}
|
|
else if (isArrayLikeObject(objValue)) {
|
|
newValue = copyArray(objValue);
|
|
}
|
|
else {
|
|
isCommon = false;
|
|
newValue = baseClone(srcValue);
|
|
}
|
|
}
|
|
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
|
if (isArguments(objValue)) {
|
|
newValue = toPlainObject(objValue);
|
|
}
|
|
else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
|
|
isCommon = false;
|
|
newValue = baseClone(srcValue);
|
|
}
|
|
else {
|
|
newValue = srcIndex ? baseClone(objValue) : objValue;
|
|
}
|
|
}
|
|
else {
|
|
isCommon = false;
|
|
}
|
|
}
|
|
stack.set(srcValue, newValue);
|
|
|
|
if (isCommon) {
|
|
// Recursively merge objects and arrays (susceptible to call stack limits).
|
|
mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
|
|
}
|
|
assignMergeValue(object, key, newValue);
|
|
}
|
|
|
|
module.exports = baseMergeDeep;
|