mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Rework how "chaining" methods are modularized.
Former-commit-id: 2986db5039ac031d1007c7376a60f41fc3eafece
This commit is contained in:
124
build.js
124
build.js
@@ -68,7 +68,8 @@
|
|||||||
'tail': 'rest',
|
'tail': 'rest',
|
||||||
'take': 'first',
|
'take': 'first',
|
||||||
'unique': 'uniq',
|
'unique': 'uniq',
|
||||||
'unzip': 'zip'
|
'unzip': 'zip',
|
||||||
|
'value': 'wrapperValueOf'
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Used to associate real names with their aliases */
|
/** Used to associate real names with their aliases */
|
||||||
@@ -87,6 +88,7 @@
|
|||||||
'rest': ['drop', 'tail'],
|
'rest': ['drop', 'tail'],
|
||||||
'some': ['any'],
|
'some': ['any'],
|
||||||
'uniq': ['unique'],
|
'uniq': ['unique'],
|
||||||
|
'wrapperValueOf': ['value'],
|
||||||
'zip': ['unzip'],
|
'zip': ['unzip'],
|
||||||
'zipObject': ['object']
|
'zipObject': ['object']
|
||||||
};
|
};
|
||||||
@@ -110,6 +112,7 @@
|
|||||||
'bind': ['createBound'],
|
'bind': ['createBound'],
|
||||||
'bindAll': ['baseFlatten', 'bind', 'functions'],
|
'bindAll': ['baseFlatten', 'bind', 'functions'],
|
||||||
'bindKey': ['createBound'],
|
'bindKey': ['createBound'],
|
||||||
|
'chain': [],
|
||||||
'clone': ['baseClone', 'baseCreateCallback'],
|
'clone': ['baseClone', 'baseCreateCallback'],
|
||||||
'cloneDeep': ['baseClone', 'baseCreateCallback'],
|
'cloneDeep': ['baseClone', 'baseCreateCallback'],
|
||||||
'compact': [],
|
'compact': [],
|
||||||
@@ -199,7 +202,7 @@
|
|||||||
'some': ['baseEach', 'createCallback', 'isArray'],
|
'some': ['baseEach', 'createCallback', 'isArray'],
|
||||||
'sortBy': ['compareAscending', 'createCallback', 'forEach', 'getObject', 'releaseObject'],
|
'sortBy': ['compareAscending', 'createCallback', 'forEach', 'getObject', 'releaseObject'],
|
||||||
'sortedIndex': ['createCallback', 'identity'],
|
'sortedIndex': ['createCallback', 'identity'],
|
||||||
'tap': ['value'],
|
'tap': [],
|
||||||
'template': ['defaults', 'escape', 'escapeStringChar', 'keys', 'values'],
|
'template': ['defaults', 'escape', 'escapeStringChar', 'keys', 'values'],
|
||||||
'throttle': ['debounce', 'getObject', 'isObject', 'releaseObject'],
|
'throttle': ['debounce', 'getObject', 'isObject', 'releaseObject'],
|
||||||
'times': ['baseCreateCallback'],
|
'times': ['baseCreateCallback'],
|
||||||
@@ -209,11 +212,13 @@
|
|||||||
'union': ['baseFlatten', 'baseUniq'],
|
'union': ['baseFlatten', 'baseUniq'],
|
||||||
'uniq': ['baseUniq', 'createCallback'],
|
'uniq': ['baseUniq', 'createCallback'],
|
||||||
'uniqueId': [],
|
'uniqueId': [],
|
||||||
'value': ['baseEach', 'forOwn', 'isArray', 'lodash', 'mixin', 'lodashWrapper'],
|
|
||||||
'values': ['keys'],
|
'values': ['keys'],
|
||||||
'where': ['filter'],
|
'where': ['filter'],
|
||||||
'without': ['difference'],
|
'without': ['difference'],
|
||||||
'wrap': [],
|
'wrap': [],
|
||||||
|
'wrapperChain': [],
|
||||||
|
'wrapperToString': [],
|
||||||
|
'wrapperValueOf': ['baseEach', 'forOwn', 'lodashWrapper', 'wrapperChain', 'wrapperToString'],
|
||||||
'zip': ['max', 'pluck'],
|
'zip': ['max', 'pluck'],
|
||||||
'zipObject': [],
|
'zipObject': [],
|
||||||
|
|
||||||
@@ -243,7 +248,7 @@
|
|||||||
'isNode': [],
|
'isNode': [],
|
||||||
'iteratorTemplate': [],
|
'iteratorTemplate': [],
|
||||||
'lodash': ['lodashWrapper'],
|
'lodash': ['lodashWrapper'],
|
||||||
'lodashWrapper': ['wrapperChain', 'wrapperToString', 'wrapperValueOf'],
|
'lodashWrapper': [],
|
||||||
'noop': [],
|
'noop': [],
|
||||||
'releaseArray': [],
|
'releaseArray': [],
|
||||||
'releaseObject': [],
|
'releaseObject': [],
|
||||||
@@ -252,12 +257,8 @@
|
|||||||
'shimKeys': ['createIterator'],
|
'shimKeys': ['createIterator'],
|
||||||
'slice': [],
|
'slice': [],
|
||||||
'unescapeHtmlChar': [],
|
'unescapeHtmlChar': [],
|
||||||
'wrapperChain': [],
|
|
||||||
'wrapperToString': [],
|
|
||||||
'wrapperValueOf': [],
|
|
||||||
|
|
||||||
// functions used by the `backbone` and `underscore` builds
|
// used by the `backbone` and `underscore` builds
|
||||||
'chain': ['value'],
|
|
||||||
'findWhere': ['where']
|
'findWhere': ['where']
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -348,7 +349,9 @@
|
|||||||
'Chaining': [
|
'Chaining': [
|
||||||
'chain',
|
'chain',
|
||||||
'tap',
|
'tap',
|
||||||
'value'
|
'wrapperChain',
|
||||||
|
'wrapperToString',
|
||||||
|
'wrapperValueOf'
|
||||||
],
|
],
|
||||||
'Collections': [
|
'Collections': [
|
||||||
'at',
|
'at',
|
||||||
@@ -506,7 +509,9 @@
|
|||||||
'uniqueId',
|
'uniqueId',
|
||||||
'value',
|
'value',
|
||||||
'values',
|
'values',
|
||||||
'without'
|
'without',
|
||||||
|
'wrapperChain',
|
||||||
|
'wrapperValueOf'
|
||||||
];
|
];
|
||||||
|
|
||||||
/** List of all function categories */
|
/** List of all function categories */
|
||||||
@@ -607,8 +612,7 @@
|
|||||||
'shimKeys',
|
'shimKeys',
|
||||||
'slice',
|
'slice',
|
||||||
'unescapeHtmlChar',
|
'unescapeHtmlChar',
|
||||||
'wrapperToString',
|
'wrapperToString'
|
||||||
'wrapperValueOf'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/** List of all property dependencies */
|
/** List of all property dependencies */
|
||||||
@@ -748,16 +752,20 @@
|
|||||||
].join('\n' + indent);
|
].join('\n' + indent);
|
||||||
});
|
});
|
||||||
|
|
||||||
// move `mixin(lodash)` to after the method assignments
|
// move `mixin(lodash)`
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\s*mixin\(lodash\).+/, '');
|
|
||||||
source = source.replace(getMethodAssignments(source), function(match) {
|
source = source.replace(getMethodAssignments(source), function(match) {
|
||||||
var indent = /^ *(?=lodash\.)/m.exec(match)[0];
|
// remove `mixin(lodash)`
|
||||||
return match + [
|
match = match.replace(/(?:\s*\/\/.*)*\s*mixin\(lodash\).+/, '');
|
||||||
'',
|
|
||||||
'// add functions to `lodash.prototype`',
|
// insert `mixin(lodash)` before `_.VERSION`
|
||||||
'mixin(lodash);',
|
return match.replace(/(?:\n *\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n( *)lodash\.VERSION/, function(match, indent) {
|
||||||
''
|
return [
|
||||||
].join('\n' + indent);
|
'',
|
||||||
|
'// add functions to `lodash.prototype`',
|
||||||
|
'mixin(lodash);',
|
||||||
|
match
|
||||||
|
].join('\n' + indent);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
@@ -1336,11 +1344,7 @@
|
|||||||
* @returns {String} Returns the method assignments snippet.
|
* @returns {String} Returns the method assignments snippet.
|
||||||
*/
|
*/
|
||||||
function getMethodAssignments(source) {
|
function getMethodAssignments(source) {
|
||||||
var result = source.match(RegExp(
|
var result = source.match(/\n\n(?:\s*\/\/.*)*\s*lodash\.\w+ *=[\s\S]+lodash\.\w+ *=.+/);
|
||||||
'(?:\\n\\n(?:\\s*//.*)*\\s*lodash\\.\\w+ *=[\\s\\S]+?)?' +
|
|
||||||
multilineComment +
|
|
||||||
' *lodash\\.VERSION *=[\\s\\S]+?;\\n'
|
|
||||||
));
|
|
||||||
return result ? result[0] : '';
|
return result ? result[0] : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1825,6 +1829,7 @@
|
|||||||
*/
|
*/
|
||||||
function removeLodashWrapper(source) {
|
function removeLodashWrapper(source) {
|
||||||
source = removeFunction(source, 'lodashWrapper');
|
source = removeFunction(source, 'lodashWrapper');
|
||||||
|
source = removeSpliceObjectsFix(source);
|
||||||
|
|
||||||
// remove `lodashWrapper.prototype` assignment
|
// remove `lodashWrapper.prototype` assignment
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\n *lodashWrapper\.prototype *=.+/, '');
|
source = source.replace(/(?:\s*\/\/.*)*\n *lodashWrapper\.prototype *=.+/, '');
|
||||||
@@ -1832,6 +1837,19 @@
|
|||||||
// replace `new lodashWrapper` with `new lodash`
|
// replace `new lodashWrapper` with `new lodash`
|
||||||
source = source.replace(/\bnew lodashWrapper\b/g, 'new lodash');
|
source = source.replace(/\bnew lodashWrapper\b/g, 'new lodash');
|
||||||
|
|
||||||
|
// remove all `lodash.prototype` additions
|
||||||
|
source = source
|
||||||
|
.replace(/(?:\s*\/\/.*)*\n( *)forOwn\(lodash,[\s\S]+?\n\1}.+/g, '')
|
||||||
|
.replace(/(?:\s*\/\/.*)*\n( *)(?:baseEach|forEach)\(\['[\s\S]+?\n\1}.+/g, '')
|
||||||
|
.replace(/(?:\s*\/\/.*)*\n *lodash\.prototype\.[\s\S]+?;/g, '');
|
||||||
|
|
||||||
|
// replace `lodash` with a simpler version
|
||||||
|
source = replaceFunction(source, 'lodash', [
|
||||||
|
'function lodash() {',
|
||||||
|
' // no operation performed',
|
||||||
|
'}'
|
||||||
|
].join('\n'));
|
||||||
|
|
||||||
// remove `lodashWrapper` from `_.mixin`
|
// remove `lodashWrapper` from `_.mixin`
|
||||||
source = source.replace(matchFunction(source, 'mixin'), function(match) {
|
source = source.replace(matchFunction(source, 'mixin'), function(match) {
|
||||||
return match
|
return match
|
||||||
@@ -2764,6 +2782,9 @@
|
|||||||
if (!isLodash('baseClone') && !isLodash('clone') && !isLodash('cloneDeep')) {
|
if (!isLodash('baseClone') && !isLodash('clone') && !isLodash('cloneDeep')) {
|
||||||
_.pull(funcDepMap.clone, 'baseClone').push('assign', 'isArray', 'isObject');
|
_.pull(funcDepMap.clone, 'baseClone').push('assign', 'isArray', 'isObject');
|
||||||
}
|
}
|
||||||
|
if (!isLodash('chain')) {
|
||||||
|
_.pull(funcDepMap.wrapperValueOf, 'wrapperToString');
|
||||||
|
}
|
||||||
if (!isLodash('contains')) {
|
if (!isLodash('contains')) {
|
||||||
_.pull(funcDepMap.contains, 'isString');
|
_.pull(funcDepMap.contains, 'isString');
|
||||||
}
|
}
|
||||||
@@ -2834,6 +2855,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_.forOwn(varDepMap, function(deps, funcName) {
|
||||||
|
if (!isLodash(funcName)) {
|
||||||
|
_.pull(deps, 'arrayPool', 'largeArraySize', 'maxPoolSize', 'objectPool');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (isModern || isUnderscore) {
|
if (isModern || isUnderscore) {
|
||||||
_.each(['assign', 'baseEach', 'defaults', 'forIn', 'forOwn', 'shimKeys'], function(funcName) {
|
_.each(['assign', 'baseEach', 'defaults', 'forIn', 'forOwn', 'shimKeys'], function(funcName) {
|
||||||
@@ -2883,7 +2910,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!isMobile) {
|
if (!isMobile) {
|
||||||
_.each(['baseClone', 'transform', 'value'], function(funcName) {
|
_.each(['baseClone', 'transform', 'wrapperValueOf'], function(funcName) {
|
||||||
_.pull(funcDepMap[funcName], 'baseEach').push('forEach');
|
_.pull(funcDepMap[funcName], 'baseEach').push('forEach');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2905,6 +2932,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isModularize) {
|
if (isModularize) {
|
||||||
|
funcDepMap.wrapperValueOf.length = 0;
|
||||||
|
|
||||||
_.forOwn(funcDepMap, function(deps, funcName) {
|
_.forOwn(funcDepMap, function(deps, funcName) {
|
||||||
if (_.contains(deps, 'getIndexOf')) {
|
if (_.contains(deps, 'getIndexOf')) {
|
||||||
_.pull(deps, 'getIndexOf').push('baseIndexOf');
|
_.pull(deps, 'getIndexOf').push('baseIndexOf');
|
||||||
@@ -3957,7 +3986,6 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (isModularize) {
|
if (isModularize) {
|
||||||
source = removeAssignments(source);
|
|
||||||
source = removeGetIndexOf(source);
|
source = removeGetIndexOf(source);
|
||||||
|
|
||||||
// replace the `lodash.templateSettings` property assignment with a variable assignment
|
// replace the `lodash.templateSettings` property assignment with a variable assignment
|
||||||
@@ -3978,13 +4006,6 @@
|
|||||||
source = source.replace(matchProp(source, 'templateSettings'), function(match) {
|
source = source.replace(matchProp(source, 'templateSettings'), function(match) {
|
||||||
return match.replace(/(:\s*)lodash\b/, "$1{ 'escape': escape }");
|
return match.replace(/(:\s*)lodash\b/, "$1{ 'escape': escape }");
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove function aliases
|
|
||||||
_.each(buildFuncs, function(funcName) {
|
|
||||||
_.each(getAliases(funcName, funcDepMap), function(alias) {
|
|
||||||
source = removeFunction(source, alias);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4071,28 +4092,12 @@
|
|||||||
|
|
||||||
// modify/remove references to removed functions/variables
|
// modify/remove references to removed functions/variables
|
||||||
if (!isTemplate) {
|
if (!isTemplate) {
|
||||||
if (isExcluded('lodashWrapper')) {
|
if (isExcluded('mixin')) {
|
||||||
source = removeLodashWrapper(source);
|
|
||||||
|
|
||||||
// simplify the `lodash` function
|
|
||||||
source = replaceFunction(source, 'lodash', [
|
|
||||||
'function lodash() {',
|
|
||||||
' // no operation performed',
|
|
||||||
'}'
|
|
||||||
].join('\n'));
|
|
||||||
}
|
|
||||||
if (isExcluded('mixin') || isExcluded('value')) {
|
|
||||||
// remove `_.mixin` call
|
// remove `_.mixin` call
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\s*mixin\(lodash\).+/, '');
|
source = source.replace(/(?:\s*\/\/.*)*\s*mixin\(lodash\).+/, '');
|
||||||
}
|
}
|
||||||
if (isExcluded('value')) {
|
if (isExcluded('lodashWrapper')) {
|
||||||
source = removeSpliceObjectsFix(source);
|
source = removeLodashWrapper(source);
|
||||||
|
|
||||||
// remove all `lodash.prototype` additions
|
|
||||||
source = source
|
|
||||||
.replace(/(?:\s*\/\/.*)*\n( *)forOwn\(lodash,[\s\S]+?\n\1}.+/g, '')
|
|
||||||
.replace(/(?:\s*\/\/.*)*\n( *)(?:baseEach|forEach)\(\['[\s\S]+?\n\1}.+/g, '')
|
|
||||||
.replace(/(?:\s*\/\/.*)*\n *lodash\.prototype\.[\s\S]+?;/g, '');
|
|
||||||
}
|
}
|
||||||
if (!isNoDep) {
|
if (!isNoDep) {
|
||||||
if (isExcluded('bind')) {
|
if (isExcluded('bind')) {
|
||||||
@@ -4122,9 +4127,6 @@
|
|||||||
source = removeFromGetObject(source, prop);
|
source = removeFromGetObject(source, prop);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (isExcluded('value')) {
|
|
||||||
source = removeSupportSpliceObjects(source);
|
|
||||||
}
|
|
||||||
if (!/\.(?:enumErrorProps|nonEnumShadows) *=/.test(source)) {
|
if (!/\.(?:enumErrorProps|nonEnumShadows) *=/.test(source)) {
|
||||||
source = removeFromCreateIterator(source, 'errorClass');
|
source = removeFromCreateIterator(source, 'errorClass');
|
||||||
source = removeFromCreateIterator(source, 'errorProto');
|
source = removeFromCreateIterator(source, 'errorProto');
|
||||||
@@ -4149,6 +4151,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove functions from the build
|
// remove functions from the build
|
||||||
allFuncs.forEach(function(funcName) {
|
allFuncs.forEach(function(funcName) {
|
||||||
if (!_.contains(buildFuncs, funcName) &&
|
if (!_.contains(buildFuncs, funcName) &&
|
||||||
@@ -4243,12 +4246,9 @@
|
|||||||
}());
|
}());
|
||||||
|
|
||||||
if (isNoDep) {
|
if (isNoDep) {
|
||||||
source = removeAssignments(source);
|
|
||||||
source = removeGetIndexOf(source);
|
|
||||||
source = removeLodashWrapper(source);
|
|
||||||
|
|
||||||
if (isExcluded('lodash')) {
|
if (isExcluded('lodash')) {
|
||||||
source = removeFunction(source, 'lodash');
|
source = removeFunction(source, 'lodash');
|
||||||
|
source = removeAssignments(source);
|
||||||
}
|
}
|
||||||
// remove unneeded variable dependencies
|
// remove unneeded variable dependencies
|
||||||
_.each(varDependencies, function(varName) {
|
_.each(varDependencies, function(varName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user