mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Add templateSettings to funcDependencyMap, add reNative to varDependencyMap, and simplify support property cleanup.
Former-commit-id: 0c55084b4479bb8213a3387fc246f36ca3f185dd
This commit is contained in:
64
build.js
64
build.js
@@ -79,6 +79,10 @@
|
|||||||
|
|
||||||
/** Used to track function dependencies */
|
/** Used to track function dependencies */
|
||||||
var funcDependencyMap = {
|
var funcDependencyMap = {
|
||||||
|
// properties
|
||||||
|
'templateSettings': ['escape'],
|
||||||
|
|
||||||
|
// public functions
|
||||||
'after': [],
|
'after': [],
|
||||||
'assign': ['createCallback', 'createIterator'],
|
'assign': ['createCallback', 'createIterator'],
|
||||||
'at': ['isString'],
|
'at': ['isString'],
|
||||||
@@ -215,7 +219,7 @@
|
|||||||
'wrapperToString': [],
|
'wrapperToString': [],
|
||||||
'wrapperValueOf': [],
|
'wrapperValueOf': [],
|
||||||
|
|
||||||
// used by the `backbone` and `underscore` builds
|
// functions used by the `backbone` and `underscore` builds
|
||||||
'chain': ['value'],
|
'chain': ['value'],
|
||||||
'findWhere': ['where']
|
'findWhere': ['where']
|
||||||
};
|
};
|
||||||
@@ -239,17 +243,23 @@
|
|||||||
|
|
||||||
/** Used to track variable dependencies of functions */
|
/** Used to track variable dependencies of functions */
|
||||||
var varDependencyMap = {
|
var varDependencyMap = {
|
||||||
|
'bind': ['reNative'],
|
||||||
'bindKey': ['indicatorObject'],
|
'bindKey': ['indicatorObject'],
|
||||||
'createCallback': ['indicatorObject'],
|
'createCallback': ['indicatorObject'],
|
||||||
'createIterator': ['indicatorObject', 'iteratorObject', 'objectTypes'],
|
'createIterator': ['indicatorObject', 'iteratorObject', 'objectTypes'],
|
||||||
'defer': ['objectTypes'],
|
'createObject': ['reNative'],
|
||||||
|
'defer': ['objectTypes', 'reNative'],
|
||||||
|
'isArray': ['reNative'],
|
||||||
'isEqual': ['indicatorObject'],
|
'isEqual': ['indicatorObject'],
|
||||||
'isObject': ['objectTypes'],
|
'isObject': ['objectTypes'],
|
||||||
|
'isPlainObject': ['reNative'],
|
||||||
'isRegExp': ['objectTypes'],
|
'isRegExp': ['objectTypes'],
|
||||||
'keys': ['iteratorObject'],
|
'keys': ['iteratorObject', 'reNative'],
|
||||||
'merge': ['indicatorObject'],
|
'merge': ['indicatorObject'],
|
||||||
'partialRight': ['indicatorObject'],
|
'partialRight': ['indicatorObject'],
|
||||||
'template': ['reInterpolate']
|
'support': ['reNative'],
|
||||||
|
'template': ['reInterpolate'],
|
||||||
|
'templateSettings': ['reInterpolate']
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Used to track the category of identifiers */
|
/** Used to track the category of identifiers */
|
||||||
@@ -521,7 +531,10 @@
|
|||||||
];
|
];
|
||||||
|
|
||||||
/** List of all functions */
|
/** List of all functions */
|
||||||
var allFuncs = _.keys(funcDependencyMap);
|
var allFuncs = _.keys(funcDependencyMap).filter(function(key) {
|
||||||
|
var type = typeof _[key];
|
||||||
|
return type == 'function' || type == 'undefined';
|
||||||
|
});
|
||||||
|
|
||||||
/** List of Lo-Dash functions */
|
/** List of Lo-Dash functions */
|
||||||
var lodashFuncs = _.difference(allFuncs, privateFuncs, 'findWhere');
|
var lodashFuncs = _.difference(allFuncs, privateFuncs, 'findWhere');
|
||||||
@@ -822,9 +835,6 @@
|
|||||||
.concat(varDependencyMap[identifier] || [])
|
.concat(varDependencyMap[identifier] || [])
|
||||||
.sort();
|
.sort();
|
||||||
|
|
||||||
if (identifier == 'templateSettings') {
|
|
||||||
deps = ['escape', 'reInterpolate'];
|
|
||||||
}
|
|
||||||
var modulePath = getPath(identifier),
|
var modulePath = getPath(identifier),
|
||||||
depArgs = deps.join(', '),
|
depArgs = deps.join(', '),
|
||||||
depPaths = '[' + (deps.length ? "'" + getDepPaths(deps, modulePath).join("', '") + "'" : '') + '], ',
|
depPaths = '[' + (deps.length ? "'" + getDepPaths(deps, modulePath).join("', '") + "'" : '') + '], ',
|
||||||
@@ -1747,7 +1757,7 @@
|
|||||||
function removeProp(source, propName) {
|
function removeProp(source, propName) {
|
||||||
return source.replace(RegExp(
|
return source.replace(RegExp(
|
||||||
multilineComment +
|
multilineComment +
|
||||||
'(?: *|(.*?=))lodash\\.' + propName + '\\s*=[\\s\\S]+?' +
|
'(?: *|(.*?=))lodash\\._?' + propName + '\\s*=[\\s\\S]+?' +
|
||||||
'(?:\\(function[\\s\\S]+?\\([^)]*\\)\\);\\n(?=\\n)|' +
|
'(?:\\(function[\\s\\S]+?\\([^)]*\\)\\);\\n(?=\\n)|' +
|
||||||
'[;}]\\n(?=\\n(?!\\s*\\(func)))'
|
'[;}]\\n(?=\\n(?!\\s*\\(func)))'
|
||||||
), function(match, prelude) {
|
), function(match, prelude) {
|
||||||
@@ -2440,8 +2450,9 @@
|
|||||||
var categories = _.intersection(funcNames, allCategories);
|
var categories = _.intersection(funcNames, allCategories);
|
||||||
|
|
||||||
categories.forEach(function(category) {
|
categories.forEach(function(category) {
|
||||||
var otherFuncs = getNamesByCategory(category).filter(function(identifier) {
|
var otherFuncs = getNamesByCategory(category).filter(function(key) {
|
||||||
return typeof _[identifier] == 'function';
|
var type = typeof _[key];
|
||||||
|
return type == 'function' || type == 'undefined';
|
||||||
});
|
});
|
||||||
|
|
||||||
// limit function names to those available for specific builds
|
// limit function names to those available for specific builds
|
||||||
@@ -2556,6 +2567,10 @@
|
|||||||
funcDependencyMap.defer = _.without(funcDependencyMap.defer, 'bind');
|
funcDependencyMap.defer = _.without(funcDependencyMap.defer, 'bind');
|
||||||
funcDependencyMap.isPlainObject = _.without(funcDependencyMap.isPlainObject, 'shimIsPlainObject');
|
funcDependencyMap.isPlainObject = _.without(funcDependencyMap.isPlainObject, 'shimIsPlainObject');
|
||||||
funcDependencyMap.keys = _.without(funcDependencyMap.keys, 'shimKeys');
|
funcDependencyMap.keys = _.without(funcDependencyMap.keys, 'shimKeys');
|
||||||
|
|
||||||
|
_.forOwn(varDependencyMap, function(deps, varName) {
|
||||||
|
varDependencyMap[varName] = _.without(deps, 'reNative');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
_.each(['assign', 'defaults'], function(funcName) {
|
_.each(['assign', 'defaults'], function(funcName) {
|
||||||
@@ -3914,7 +3929,7 @@
|
|||||||
source = source
|
source = source
|
||||||
.replace(/(?:\s*\/\/.*)*\n( *)forOwn\(lodash,[\s\S]+?\n\1}.+/g, '')
|
.replace(/(?:\s*\/\/.*)*\n( *)forOwn\(lodash,[\s\S]+?\n\1}.+/g, '')
|
||||||
.replace(/(?:\s*\/\/.*)*\n( *)(?:basicEach|forEach)\(\['[\s\S]+?\n\1}.+/g, '')
|
.replace(/(?:\s*\/\/.*)*\n( *)(?:basicEach|forEach)\(\['[\s\S]+?\n\1}.+/g, '')
|
||||||
.replace(/(?:\s*\/\/.*)*\n *lodash\.prototype.[\s\S]+?;/g, '');
|
.replace(/(?:\s*\/\/.*)*\n *lodash\.prototype\.[\s\S]+?;/g, '');
|
||||||
}
|
}
|
||||||
if (isNoDep) {
|
if (isNoDep) {
|
||||||
source = removeAssignments(source);
|
source = removeAssignments(source);
|
||||||
@@ -3970,13 +3985,15 @@
|
|||||||
if (isExcluded('value')) {
|
if (isExcluded('value')) {
|
||||||
source = removeSupportSpliceObjects(source);
|
source = removeSupportSpliceObjects(source);
|
||||||
}
|
}
|
||||||
if (!/^ *support\.(?:enumErrorProps|nonEnumShadows) *=/m.test(source)) {
|
if (!/\.(?:enumErrorProps|nonEnumShadows) *=/.test(source)) {
|
||||||
source = removeFromCreateIterator(source, 'errorClass');
|
source = removeFromCreateIterator(source, 'errorClass');
|
||||||
source = removeFromCreateIterator(source, 'errorProto');
|
source = removeFromCreateIterator(source, 'errorProto');
|
||||||
|
|
||||||
// remove 'Error' from the `contextProps` array
|
// remove 'Error' from the `contextProps` array
|
||||||
source = source.replace(/^ *var contextProps *=[\s\S]+?;/m, function(match) {
|
source = source.replace(/^ *var contextProps *=[\s\S]+?;/m, function(match) {
|
||||||
return match.replace(/'Error', */, '');
|
return match
|
||||||
|
.replace(/'Error',? */, '')
|
||||||
|
.replace(/,(?=\s*])/, '');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4000,7 +4017,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove unneeded function properties dependencies
|
// remove unneeded property dependencies
|
||||||
_.each(propDependencies, function(propName) {
|
_.each(propDependencies, function(propName) {
|
||||||
if (!_.contains(includeProps, propName)) {
|
if (!_.contains(includeProps, propName)) {
|
||||||
source = removeProp(source, propName);
|
source = removeProp(source, propName);
|
||||||
@@ -4039,19 +4056,19 @@
|
|||||||
return match.replace(/^ *\(function[\s\S]+?\n(( *)var ctor *=[\s\S]+?(?:\n *for.+)+\n)([\s\S]+?)}\(1\)\);\n/m, function(match, setup, indent, body) {
|
return match.replace(/^ *\(function[\s\S]+?\n(( *)var ctor *=[\s\S]+?(?:\n *for.+)+\n)([\s\S]+?)}\(1\)\);\n/m, function(match, setup, indent, body) {
|
||||||
var modified = setup;
|
var modified = setup;
|
||||||
|
|
||||||
if (!/support\.spliceObjects *=(?! *(?:false|true))/.test(body)) {
|
if (!/\.spliceObjects *=(?! *(?:false|true))/.test(body)) {
|
||||||
modified = modified.replace(/^ *object *=.+\n/m, '');
|
modified = modified.replace(/^ *object *=.+\n/m, '');
|
||||||
}
|
}
|
||||||
if (!/support\.enumPrototypes *=(?! *(?:false|true))/.test(body) &&
|
if (!/\.enumPrototypes *=(?! *(?:false|true))/.test(body) &&
|
||||||
!/support\.nonEnumShadows *=(?! *(?:false|true))/.test(body) &&
|
!/\.nonEnumShadows *=(?! *(?:false|true))/.test(body) &&
|
||||||
!/support\.ownLast *=(?! *(?:false|true))/.test(body)) {
|
!/\.ownLast *=(?! *(?:false|true))/.test(body)) {
|
||||||
modified = modified
|
modified = modified
|
||||||
.replace(/\bctor *=.+\s+/, '')
|
.replace(/\bctor *=.+\s+/, '')
|
||||||
.replace(/^ *ctor\.prototype.+\s+.+\n/m, '')
|
.replace(/^ *ctor\.prototype.+\s+.+\n/m, '')
|
||||||
.replace(/(?:,\n)? *props *=[^;=]+/, '')
|
.replace(/(?:,\n)? *props *=[^;=]+/, '')
|
||||||
.replace(/^ *for *\((?=prop)/, '$&var ')
|
.replace(/^ *for *\((?=prop)/, '$&var ')
|
||||||
}
|
}
|
||||||
if (!/support\.nonEnumArgs *=(?! *(?:false|true))/.test(body)) {
|
if (!/\.nonEnumArgs *=(?! *(?:false|true))/.test(body)) {
|
||||||
modified = modified.replace(/^ *for *\(.+? arguments.+\n/m, '');
|
modified = modified.replace(/^ *for *\(.+? arguments.+\n/m, '');
|
||||||
}
|
}
|
||||||
// cleanup the empty var statement
|
// cleanup the empty var statement
|
||||||
@@ -4083,6 +4100,13 @@
|
|||||||
source = source.replace(matchVar(source, 'templateSettings'), function(match) {
|
source = source.replace(matchVar(source, 'templateSettings'), function(match) {
|
||||||
return match.replace(/(:\s*)lodash\b/, "$1{ 'escape': escape }");
|
return match.replace(/(:\s*)lodash\b/, "$1{ 'escape': escape }");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// remove unneeded variable dependencies
|
||||||
|
_.each(varDependencies, function(varName) {
|
||||||
|
if (!_.contains(includeVars, varName)) {
|
||||||
|
source = removeVar(source, varName);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_.size(source.match(/\bfreeModule\b/g)) < 2) {
|
if (_.size(source.match(/\bfreeModule\b/g)) < 2) {
|
||||||
|
|||||||
@@ -1664,7 +1664,8 @@
|
|||||||
// expand categories to function names
|
// expand categories to function names
|
||||||
funcNames.slice().forEach(function(category) {
|
funcNames.slice().forEach(function(category) {
|
||||||
var otherNames = _.filter(categoryMap[category], function(key) {
|
var otherNames = _.filter(categoryMap[category], function(key) {
|
||||||
return typeof _[key] == 'function';
|
var type = typeof _[key];
|
||||||
|
return type == 'function' || type == 'undefined';
|
||||||
});
|
});
|
||||||
|
|
||||||
// limit function names to those available for specific builds
|
// limit function names to those available for specific builds
|
||||||
|
|||||||
Reference in New Issue
Block a user