mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Cleanup build.js and update dependencies for _.clone, _.isEmpty, _.isEqual, _.merge, and _.size.
Former-commit-id: df19990609a3dd8432694798149a5eb5bda142c4
This commit is contained in:
130
build.js
130
build.js
@@ -153,7 +153,7 @@
|
|||||||
'bind': [],
|
'bind': [],
|
||||||
'bindAll': ['bind', 'functions'],
|
'bindAll': ['bind', 'functions'],
|
||||||
'chain': ['mixin'],
|
'chain': ['mixin'],
|
||||||
'clone': ['extend', 'forOwn', 'isArguments'],
|
'clone': ['extend', 'forIn', 'forOwn', 'isArguments'],
|
||||||
'compact': [],
|
'compact': [],
|
||||||
'compose': [],
|
'compose': [],
|
||||||
'contains': [],
|
'contains': [],
|
||||||
@@ -187,8 +187,8 @@
|
|||||||
'isBoolean': [],
|
'isBoolean': [],
|
||||||
'isDate': [],
|
'isDate': [],
|
||||||
'isElement': [],
|
'isElement': [],
|
||||||
'isEmpty': [],
|
'isEmpty': ['isArguments'],
|
||||||
'isEqual': [],
|
'isEqual': ['isArguments'],
|
||||||
'isFinite': [],
|
'isFinite': [],
|
||||||
'isFunction': [],
|
'isFunction': [],
|
||||||
'isNaN': [],
|
'isNaN': [],
|
||||||
@@ -204,7 +204,7 @@
|
|||||||
'map': ['identity'],
|
'map': ['identity'],
|
||||||
'max': [],
|
'max': [],
|
||||||
'memoize': [],
|
'memoize': [],
|
||||||
'merge': ['isArray'],
|
'merge': ['isArray', 'forIn'],
|
||||||
'min': [],
|
'min': [],
|
||||||
'mixin': ['forEach', 'functions'],
|
'mixin': ['forEach', 'functions'],
|
||||||
'noConflict': [],
|
'noConflict': [],
|
||||||
@@ -219,7 +219,7 @@
|
|||||||
'rest': [],
|
'rest': [],
|
||||||
'result': [],
|
'result': [],
|
||||||
'shuffle': [],
|
'shuffle': [],
|
||||||
'size': ['keys'],
|
'size': ['isArguments', 'keys'],
|
||||||
'some': ['identity'],
|
'some': ['identity'],
|
||||||
'sortBy': [],
|
'sortBy': [],
|
||||||
'sortedIndex': ['bind'],
|
'sortedIndex': ['bind'],
|
||||||
@@ -488,7 +488,7 @@
|
|||||||
function removeFromCreateIterator(source, refName) {
|
function removeFromCreateIterator(source, refName) {
|
||||||
var snippet = matchFunction(source, 'createIterator');
|
var snippet = matchFunction(source, 'createIterator');
|
||||||
if (snippet) {
|
if (snippet) {
|
||||||
// clip the snippet the `factory` assignment
|
// clip the snippet at the `factory` assignment
|
||||||
snippet = snippet.match(/Function\([\s\S]+$/)[0];
|
snippet = snippet.match(/Function\([\s\S]+$/)[0];
|
||||||
var modified = snippet.replace(RegExp('\\b' + refName + '\\b,? *', 'g'), '');
|
var modified = snippet.replace(RegExp('\\b' + refName + '\\b,? *', 'g'), '');
|
||||||
source = source.replace(snippet, modified);
|
source = source.replace(snippet, modified);
|
||||||
@@ -560,6 +560,38 @@
|
|||||||
.replace(/\s*.+?\.isKeysFast *=.+/, '');
|
.replace(/\s*.+?\.isKeysFast *=.+/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all `noArgsClass` references from `source`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {String} source The source to process.
|
||||||
|
* @returns {String} Returns the modified source.
|
||||||
|
*/
|
||||||
|
function removeNoArgsClass(source) {
|
||||||
|
return removeVar(source, 'noArgsClass')
|
||||||
|
// remove `noArgsClass` from `_.clone`, `_.isEqual`, and `_.size`
|
||||||
|
.replace(/ *\|\| *\(noArgsClass *&&[^)]+?\)\)/g, '')
|
||||||
|
// remove `noArgsClass` from `_.isEqual`
|
||||||
|
.replace(/if *\(noArgsClass[^}]+?}\n/, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all `noNodeClass` references from `source`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {String} source The source to process.
|
||||||
|
* @returns {String} Returns the modified source.
|
||||||
|
*/
|
||||||
|
function removeNoNodeClass(source) {
|
||||||
|
return source
|
||||||
|
// remove `noNodeClass` assignment
|
||||||
|
.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *try *\{(?:\s*\/\/.*)*\n *var noNodeClass[\s\S]+?catch[^}]+}\n/, '')
|
||||||
|
// remove `noNodeClass` from `isPlainObject`
|
||||||
|
.replace(/\(!noNodeClass *\|\|[\s\S]+?\)\) *&&/, '')
|
||||||
|
// remove `noNodeClass` from `_.isEqual`
|
||||||
|
.replace(/ *\|\| *\(noNodeClass *&&[\s\S]+?\)\)\)/, '');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the "use strict" directive from `source`.
|
* Removes the "use strict" directive from `source`.
|
||||||
*
|
*
|
||||||
@@ -599,6 +631,9 @@
|
|||||||
// remove a variable at the end of a variable declaration list
|
// remove a variable at the end of a variable declaration list
|
||||||
source = source.replace(RegExp(',\\s*' + varName + ' *=.+?;'), ';');
|
source = source.replace(RegExp(',\\s*' + varName + ' *=.+?;'), ';');
|
||||||
|
|
||||||
|
// remove variable reference from `arrayLikeClasses` and `cloneableClasses` assignments
|
||||||
|
source = source.replace(RegExp('(?:arrayLikeClasses|cloneableClasses)\\[' + varName + '\\] *= *(?:false|true)?', 'g'), '');
|
||||||
|
|
||||||
return removeFromCreateIterator(source, varName);
|
return removeFromCreateIterator(source, varName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,6 +680,25 @@
|
|||||||
.replace(/\s*.+?\.useStrict *=.+/, '');
|
.replace(/\s*.+?\.useStrict *=.+/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes `source` to a file with the given `filename` to the current
|
||||||
|
* working directory.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {String} source The source to write.
|
||||||
|
* @param {String} filename The name of the file.
|
||||||
|
*/
|
||||||
|
function writeFile(source, filename) {
|
||||||
|
// correct overly aggressive Closure Compiler minification
|
||||||
|
source = source.replace('prototype={valueOf:1}', 'prototype={valueOf:1,y:1}');
|
||||||
|
|
||||||
|
// re-remove "use strict" added by the minifier
|
||||||
|
if (!useStrict) {
|
||||||
|
source = removeUseStrictDirective(source);
|
||||||
|
}
|
||||||
|
fs.writeFileSync(path.join(cwd, filename), source);
|
||||||
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// display help message
|
// display help message
|
||||||
@@ -893,41 +947,32 @@
|
|||||||
return match.replace(/\bcallee\b/g, 'merge');
|
return match.replace(/\bcallee\b/g, 'merge');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// remove `hasDontEnumBug` and `iteratesOwnLast` assignment
|
||||||
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug\b[\s\S]+?}\(\)\);\n/, '');
|
||||||
|
|
||||||
|
// remove `iteratesOwnLast` from `isPlainObject`
|
||||||
|
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(iteratesOwnLast[\s\S]+?\n\1}/, '');
|
||||||
|
|
||||||
// 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}/, '');
|
||||||
|
|
||||||
// remove IE `shift` and `splice` fix from mutator Array functions mixin
|
// remove IE `shift` and `splice` fix from mutator Array functions mixin
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(value.length *=== *0[\s\S]+?\n\1}/, '');
|
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(value.length *=== *0[\s\S]+?\n\1}/, '');
|
||||||
|
|
||||||
// remove `noArgsClass` from `_.clone`, `_.isEqual`, and `_.size`
|
|
||||||
source = source.replace(/ *\|\| *\(noArgsClass *&&[^)]+?\)\)/g, '');
|
|
||||||
|
|
||||||
// remove `noArgsClass` from `_.isEqual`
|
|
||||||
source = source.replace(/if *\(noArgsClass[^}]+?}\n/, '');
|
|
||||||
|
|
||||||
// remove `noArraySliceOnStrings` from `_.toArray`
|
// remove `noArraySliceOnStrings` from `_.toArray`
|
||||||
source = source.replace(/noArraySliceOnStrings *\?[^:]+: *([^)]+)/g, '$1');
|
source = source.replace(/noArraySliceOnStrings *\?[^:]+: *([^)]+)/g, '$1');
|
||||||
|
|
||||||
// remove `noCharByIndex` from `_.reduceRight`
|
// remove `noCharByIndex` from `_.reduceRight`
|
||||||
source = source.replace(/noCharByIndex *&&[^:]+: *([^;]+)/g, '$1');
|
source = source.replace(/noCharByIndex *&&[^:]+: *([^;]+)/g, '$1');
|
||||||
|
|
||||||
// remove `noNodeClass` assignment
|
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *try *\{(?:\s*\/\/.*)*\n *var noNodeClass[\s\S]+?catch[^}]+}\n/, '');
|
|
||||||
|
|
||||||
// remove `noNodeClass` from `isPlainObject`
|
|
||||||
source = source.replace(/\(!noNodeClass *\|\|[\s\S]+?\)\) *&&/, '');
|
|
||||||
|
|
||||||
// remove `noNodeClass` from `_.isEqual`
|
|
||||||
source = source.replace(/ *\|\| *\(noNodeClass *&&[\s\S]+?\)\)\)/, '');
|
|
||||||
|
|
||||||
source = removeVar(source, 'extendIteratorOptions');
|
source = removeVar(source, 'extendIteratorOptions');
|
||||||
source = removeVar(source, 'hasDontEnumBug');
|
|
||||||
source = removeVar(source, 'iteratorTemplate');
|
source = removeVar(source, 'iteratorTemplate');
|
||||||
source = removeVar(source, 'noArgsClass');
|
|
||||||
source = removeVar(source, 'noArraySliceOnStrings');
|
source = removeVar(source, 'noArraySliceOnStrings');
|
||||||
source = removeVar(source, 'noCharByIndex');
|
source = removeVar(source, 'noCharByIndex');
|
||||||
source = removeIsArgumentsFallback(source);
|
source = removeIsArgumentsFallback(source);
|
||||||
source = removeKeysOptimization(source);
|
source = removeKeysOptimization(source);
|
||||||
|
source = removeNoArgsClass(source);
|
||||||
|
source = removeNoNodeClass(source);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// inline `iteratorTemplate` template
|
// inline `iteratorTemplate` template
|
||||||
@@ -986,9 +1031,6 @@
|
|||||||
// remove `LoDash.prototype` additions
|
// remove `LoDash.prototype` additions
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\s*LoDash.prototype *=[\s\S]+?\/\*-+\*\//, '');
|
source = source.replace(/(?:\s*\/\/.*)*\s*LoDash.prototype *=[\s\S]+?\/\*-+\*\//, '');
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'sortBy')) {
|
|
||||||
source = removeFunction(source, 'compareAscending');
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'template')) {
|
if (isRemoved(source, 'template')) {
|
||||||
// remove `templateSettings` assignment
|
// remove `templateSettings` assignment
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *lodash\.templateSettings[\s\S]+?};\n/, '');
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *lodash\.templateSettings[\s\S]+?};\n/, '');
|
||||||
@@ -996,14 +1038,14 @@
|
|||||||
if (isRemoved(source, 'toArray')) {
|
if (isRemoved(source, 'toArray')) {
|
||||||
source = removeVar(source, 'noArraySliceOnStrings');
|
source = removeVar(source, 'noArraySliceOnStrings');
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'isArray', 'isEmpty', 'isEqual')) {
|
if (isRemoved(source, 'clone', 'merge')) {
|
||||||
source = removeVar(source, 'arrayClass');
|
source = removeFunction(source, 'isPlainObject');
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'bind', 'bindAll', 'functions', 'isEqual', 'isFunction', 'result', 'toArray')) {
|
if (isRemoved(source, 'clone', 'isArguments', 'isEmpty', 'isEqual', 'size')) {
|
||||||
source = removeVar(source, 'funcClass');
|
source = removeNoArgsClass(source);
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'bind', 'clone', 'isObject', 'keys')) {
|
if (isRemoved(source, 'isEqual', 'isPlainObject')) {
|
||||||
source = removeVar(source, 'objectTypes');
|
source = removeNoNodeClass(source);
|
||||||
}
|
}
|
||||||
if ((source.match(/\bcreateIterator\b/g) || []).length < 2) {
|
if ((source.match(/\bcreateIterator\b/g) || []).length < 2) {
|
||||||
source = removeFunction(source, 'createIterator');
|
source = removeFunction(source, 'createIterator');
|
||||||
@@ -1011,17 +1053,19 @@
|
|||||||
if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'keys')) {
|
if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'keys')) {
|
||||||
source = removeVar(source, 'reNative');
|
source = removeVar(source, 'reNative');
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'createIterator', 'extend', 'isEqual')) {
|
if (isRemoved(source, 'createIterator', 'clone', 'merge')) {
|
||||||
source = removeVar(source, 'hasDontEnumBug');
|
source = removeVar(source, 'iteratesOwnLast');
|
||||||
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var iteratesOwnLast;| +iteratesOwnLast *=.+/, '');
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'createIterator', 'contains', 'isEmpty', 'isEqual', 'isString')) {
|
if (isRemoved(source, 'createIterator', 'extend', 'isEqual', 'merge')) {
|
||||||
source = removeVar(source, 'stringClass');
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug;| +hasDontEnumBug *=.+/, '');
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'createIterator', 'keys')) {
|
if (isRemoved(source, 'createIterator', 'keys')) {
|
||||||
source = removeVar(source, 'nativeKeys');
|
source = removeVar(source, 'nativeKeys');
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'createIterator', 'reduceRight')) {
|
if (!source.match(/var (?:hasDontEnumBug|iteratesOwnLast)\b/g)) {
|
||||||
source = removeVar(source, 'noCharByIndex');
|
// remove `hasDontEnumBug` and `iteratesOwnLast` assignment
|
||||||
|
source = source.replace(/ *\(function\(\) *{\s*var props\b[\s\S]+?}\(\)\);/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove pseudo private properties
|
// remove pseudo private properties
|
||||||
@@ -1037,19 +1081,15 @@
|
|||||||
|
|
||||||
// begin the minification process
|
// begin the minification process
|
||||||
if (filterType || isBackbone || isLegacy || isMobile || isStrict || isUnderscore) {
|
if (filterType || isBackbone || isLegacy || isMobile || isStrict || isUnderscore) {
|
||||||
fs.writeFileSync(path.join(cwd, 'lodash.custom.js'), source);
|
writeFile(source, 'lodash.custom.js');
|
||||||
|
|
||||||
minify(source, 'lodash.custom.min', function(result) {
|
minify(source, 'lodash.custom.min', function(result) {
|
||||||
// re-remove "use strict" added by the minifier
|
writeFile(result, 'lodash.custom.min.js');
|
||||||
if (!useStrict) {
|
|
||||||
result = removeUseStrictDirective(result);
|
|
||||||
}
|
|
||||||
fs.writeFileSync(path.join(cwd, 'lodash.custom.min.js'), result);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
minify(source, 'lodash.min', function(result) {
|
minify(source, 'lodash.min', function(result) {
|
||||||
fs.writeFileSync(path.join(cwd, 'lodash.min.js'), result);
|
writeFile(result, 'lodash.min.js');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
|
|||||||
@@ -241,7 +241,7 @@
|
|||||||
|
|
||||||
// manually convert `arrayLikeClasses` property assignments because
|
// manually convert `arrayLikeClasses` property assignments because
|
||||||
// Closure Compiler errors trying to minify them
|
// Closure Compiler errors trying to minify them
|
||||||
source = source.replace(/(arrayLikeClasses =)[\s\S]+?= *true/g,
|
source = source.replace(/(arrayLikeClasses =)[\s\S]+?= *true/,
|
||||||
"$1{'[object Arguments]': true, '[object Array]': true, '[object Boolean]': false, " +
|
"$1{'[object Arguments]': true, '[object Array]': true, '[object Boolean]': false, " +
|
||||||
"'[object Date]': false, '[object Function]': false, '[object Number]': false, " +
|
"'[object Date]': false, '[object Function]': false, '[object Number]': false, " +
|
||||||
"'[object Object]': false, '[object RegExp]': false, '[object String]': true }"
|
"'[object Object]': false, '[object RegExp]': false, '[object String]': true }"
|
||||||
@@ -249,7 +249,7 @@
|
|||||||
|
|
||||||
// manually convert `cloneableClasses` property assignments because
|
// manually convert `cloneableClasses` property assignments because
|
||||||
// Closure Compiler errors trying to minify them
|
// Closure Compiler errors trying to minify them
|
||||||
source = source.replace(/(cloneableClasses =)[\s\S]+?= *true/g,
|
source = source.replace(/(cloneableClasses =)[\s\S]+?= *true/,
|
||||||
"$1{'[object Arguments]': false, '[object Array]': true, '[object Boolean]': true, " +
|
"$1{'[object Arguments]': false, '[object Array]': true, '[object Boolean]': true, " +
|
||||||
"'[object Date]': true, '[object Function]': false, '[object Number]': true, " +
|
"'[object Date]': true, '[object Function]': false, '[object Number]': true, " +
|
||||||
"'[object Object]': true, '[object RegExp]': true, '[object String]': true }"
|
"'[object Object]': true, '[object RegExp]': true, '[object String]': true }"
|
||||||
|
|||||||
Reference in New Issue
Block a user