mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Fix the build to work with _.merge.
Former-commit-id: cb1d9897b97b357197bb6933c65f4afbecea1aea
This commit is contained in:
5
build.js
5
build.js
@@ -888,6 +888,11 @@
|
|||||||
source = source.replace(reFunc, '$1' + getFunctionSource(lodash[funcName]) + ';\n');
|
source = source.replace(reFunc, '$1' + getFunctionSource(lodash[funcName]) + ';\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// replace `callee` in `_.merge` with `merge`
|
||||||
|
source = source.replace(matchFunction(source, 'merge'), function(match) {
|
||||||
|
return match.replace(/\bcallee\b/g, 'merge');
|
||||||
|
});
|
||||||
|
|
||||||
// remove JScript [[DontEnum]] fix from `_.isEqual`
|
// remove JScript [[DontEnum]] fix from `_.isEqual`
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasDontEnumBug[\s\S]+?\n\1}/, '');
|
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasDontEnumBug[\s\S]+?\n\1}/, '');
|
||||||
|
|
||||||
|
|||||||
@@ -7,57 +7,65 @@
|
|||||||
|
|
||||||
/** Used to minify variables embedded in compiled strings */
|
/** Used to minify variables embedded in compiled strings */
|
||||||
var compiledVars = [
|
var compiledVars = [
|
||||||
|
'callback',
|
||||||
|
'collection',
|
||||||
|
'concat',
|
||||||
|
'ctor',
|
||||||
|
'funcClass',
|
||||||
|
'hasOwnProperty',
|
||||||
|
'identity',
|
||||||
|
'index',
|
||||||
|
'iteratee',
|
||||||
|
'iterateeIndex',
|
||||||
|
'iteratorBind',
|
||||||
|
'length',
|
||||||
|
'nativeKeys',
|
||||||
|
'object',
|
||||||
|
'ownIndex',
|
||||||
|
'ownProps',
|
||||||
|
'prop',
|
||||||
|
'propertyIsEnumerable',
|
||||||
|
'propIndex',
|
||||||
|
'props',
|
||||||
|
'result',
|
||||||
|
'skipProto',
|
||||||
|
'slice',
|
||||||
|
'stringClass',
|
||||||
|
'thisArg',
|
||||||
|
'toString',
|
||||||
|
'value',
|
||||||
|
|
||||||
|
// lesser used variables
|
||||||
'accumulator',
|
'accumulator',
|
||||||
'args',
|
'args',
|
||||||
'arrayLikeClasses',
|
'arrayLikeClasses',
|
||||||
'ArrayProto',
|
'ArrayProto',
|
||||||
'bind',
|
'bind',
|
||||||
'callback',
|
|
||||||
'callee',
|
'callee',
|
||||||
'collection',
|
|
||||||
'compareAscending',
|
'compareAscending',
|
||||||
'concat',
|
|
||||||
'ctor',
|
|
||||||
'destValue',
|
'destValue',
|
||||||
'forIn',
|
'forIn',
|
||||||
'funcClass',
|
'found',
|
||||||
'funcs',
|
'funcs',
|
||||||
'hasOwnProperty',
|
|
||||||
'identity',
|
|
||||||
'index',
|
|
||||||
'indexOf',
|
'indexOf',
|
||||||
|
'indicator',
|
||||||
|
'isArguments',
|
||||||
'isArr',
|
'isArr',
|
||||||
'isArray',
|
'isArray',
|
||||||
'isArguments',
|
|
||||||
'isFunc',
|
'isFunc',
|
||||||
'isPlainObject',
|
'isPlainObject',
|
||||||
'iteratee',
|
|
||||||
'iterateeIndex',
|
|
||||||
'iteratorBind',
|
|
||||||
'length',
|
|
||||||
'methodName',
|
'methodName',
|
||||||
'nativeKeys',
|
|
||||||
'noaccum',
|
'noaccum',
|
||||||
'object',
|
|
||||||
'objectTypes',
|
'objectTypes',
|
||||||
'ownIndex',
|
|
||||||
'ownProps',
|
|
||||||
'pass',
|
'pass',
|
||||||
'prop',
|
|
||||||
'properties',
|
'properties',
|
||||||
'property',
|
'property',
|
||||||
'propertyIsEnumerable',
|
|
||||||
'propIndex',
|
|
||||||
'props',
|
|
||||||
'propsLength',
|
'propsLength',
|
||||||
'result',
|
'recursive',
|
||||||
'skipProto',
|
'source',
|
||||||
'slice',
|
'stack',
|
||||||
'stringClass',
|
'stackLength',
|
||||||
'target',
|
'target',
|
||||||
'thisArg',
|
|
||||||
'toString',
|
|
||||||
'value',
|
|
||||||
'valueProp'
|
'valueProp'
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -290,37 +298,51 @@
|
|||||||
// remove debug sourceURL use in `_.template`
|
// remove debug sourceURL use in `_.template`
|
||||||
source = source.replace(/(?:\s*\/\/.*\n)* *if *\(useSourceURL[^}]+}/, '');
|
source = source.replace(/(?:\s*\/\/.*\n)* *if *\(useSourceURL[^}]+}/, '');
|
||||||
|
|
||||||
// minify internal properties used by `_.sortBy`
|
// minify internal properties used by 'compareAscending', `_.clone`, `_.merge`, and `_.sortBy`
|
||||||
(function() {
|
(function() {
|
||||||
var properties = ['criteria', 'value'],
|
var properties = ['criteria', 'source', 'value'],
|
||||||
snippets = source.match(/( +)(?:function compareAscending|var sortBy)\b[\s\S]+?\n\1}/g);
|
snippets = source.match(/( +)(?:function clone|function compareAscending|var merge|var sortBy)\b[\s\S]+?\n\1}/g);
|
||||||
|
|
||||||
if (!snippets) {
|
if (!snippets) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
snippets.forEach(function(snippet) {
|
snippets.forEach(function(snippet) {
|
||||||
var modified = snippet,
|
var modified = snippet,
|
||||||
isSortBy = /var sortBy\b/.test(modified),
|
isCompilable = /(?:var merge|var sortBy)\b/.test(modified),
|
||||||
isInlined = !/\bcreateIterator\b/.test(modified);
|
isInlined = !/\bcreateIterator\b/.test(modified);
|
||||||
|
|
||||||
// minify properties
|
// minify properties
|
||||||
properties.forEach(function(property, index) {
|
properties.forEach(function(property, index) {
|
||||||
var reBracketProp = RegExp("\\['" + property + '\\b', 'g'),
|
var reBracketProp = RegExp("\\['(" + property + ")'\\]", 'g'),
|
||||||
reDotProp = RegExp('\\.' + property + '\\b', 'g'),
|
reDotProp = RegExp('\\.' + property + '\\b', 'g'),
|
||||||
rePropColon = RegExp('\\b' + property + ' *:', 'g');
|
rePropColon = RegExp("(')?\\b" + property + "\\1 *:", 'g');
|
||||||
|
|
||||||
// add quotes around properties in the inlined `_.sortBy` of the mobile
|
if (isCompilable) {
|
||||||
// build so Closure Compiler won't mung them
|
// add quotes around properties in the inlined `_.merge` and `_.sortBy`
|
||||||
if (isSortBy && isInlined) {
|
// of the mobile build so Closure Compiler won't mung them
|
||||||
modified = modified
|
if (isInlined) {
|
||||||
.replace(reDotProp, "['" + minNames[index] + "']")
|
modified = modified
|
||||||
.replace(rePropColon, "'" + minNames[index] + "':");
|
.replace(reBracketProp, "['" + minNames[index] + "']")
|
||||||
|
.replace(reDotProp, "['" + minNames[index] + "']")
|
||||||
|
.replace(rePropColon, "'" + minNames[index] + "':");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
modified = modified
|
||||||
|
.replace(reBracketProp, '.' + minNames[index])
|
||||||
|
.replace(reDotProp, '.' + minNames[index])
|
||||||
|
.replace(rePropColon, minNames[index] + ':');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
modified = modified
|
modified = modified
|
||||||
.replace(reBracketProp, "['" + minNames[index])
|
.replace(reBracketProp, "['" + minNames[index] + "']")
|
||||||
.replace(reDotProp, '.' + minNames[index])
|
.replace(reDotProp, '.' + minNames[index])
|
||||||
.replace(rePropColon, minNames[index] + ':');
|
.replace(rePropColon, "'" + minNames[index] + "':")
|
||||||
|
|
||||||
|
// correct `value.source` in regexp branch of `_.clone`
|
||||||
|
if (property == 'source') {
|
||||||
|
modified = modified.replace("value['" + minNames[index] + "']", "value['source']");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user