mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Adjust build for renamed variables and _.runInContext dependencies, and cleanup build.js and build/pre-compile.js.
Former-commit-id: 0d813bc111617e9b8cd922b505ec8c90ce09063b
This commit is contained in:
146
build.js
146
build.js
@@ -152,7 +152,7 @@
|
|||||||
'reject': ['filter', 'identity', 'isEqual', 'keys'],
|
'reject': ['filter', 'identity', 'isEqual', 'keys'],
|
||||||
'rest': [],
|
'rest': [],
|
||||||
'result': ['isFunction'],
|
'result': ['isFunction'],
|
||||||
'runInContext': ['extend'],
|
'runInContext': ['defaults', 'pick'],
|
||||||
'shuffle': ['forEach'],
|
'shuffle': ['forEach'],
|
||||||
'size': ['keys'],
|
'size': ['keys'],
|
||||||
'some': ['identity', 'isArray', 'isEqual', 'keys'],
|
'some': ['identity', 'isArray', 'isEqual', 'keys'],
|
||||||
@@ -191,7 +191,7 @@
|
|||||||
'loop',
|
'loop',
|
||||||
'nonEnumArgs',
|
'nonEnumArgs',
|
||||||
'noCharByIndex',
|
'noCharByIndex',
|
||||||
'shadowed',
|
'shadowedProps',
|
||||||
'top',
|
'top',
|
||||||
'useHas'
|
'useHas'
|
||||||
];
|
];
|
||||||
@@ -290,7 +290,7 @@
|
|||||||
// add `_.chain`
|
// add `_.chain`
|
||||||
source = source.replace(matchFunction(source, 'tap'), function(match) {
|
source = source.replace(matchFunction(source, 'tap'), function(match) {
|
||||||
var indent = getIndent(match);
|
var indent = getIndent(match);
|
||||||
return indent + [
|
return match && (indent + [
|
||||||
'',
|
'',
|
||||||
'/**',
|
'/**',
|
||||||
' * Creates a `lodash` object that wraps the given `value`.',
|
' * Creates a `lodash` object that wraps the given `value`.',
|
||||||
@@ -321,13 +321,13 @@
|
|||||||
'}',
|
'}',
|
||||||
'',
|
'',
|
||||||
match
|
match
|
||||||
].join('\n' + indent);
|
].join('\n' + indent));
|
||||||
});
|
});
|
||||||
|
|
||||||
// add `wrapperChain`
|
// add `wrapperChain`
|
||||||
source = source.replace(matchFunction(source, 'wrapperToString'), function(match) {
|
source = source.replace(matchFunction(source, 'wrapperToString'), function(match) {
|
||||||
var indent = getIndent(match);
|
var indent = getIndent(match);
|
||||||
return indent + [
|
return match && (indent + [
|
||||||
'',
|
'',
|
||||||
'/**',
|
'/**',
|
||||||
' * Enables method chaining on the wrapper object.',
|
' * Enables method chaining on the wrapper object.',
|
||||||
@@ -350,7 +350,7 @@
|
|||||||
'}',
|
'}',
|
||||||
'',
|
'',
|
||||||
match
|
match
|
||||||
].join('\n' + indent);
|
].join('\n' + indent));
|
||||||
});
|
});
|
||||||
|
|
||||||
// add `lodash.chain` assignment
|
// add `lodash.chain` assignment
|
||||||
@@ -937,25 +937,27 @@
|
|||||||
*/
|
*/
|
||||||
function removeFromCreateIterator(source, varName) {
|
function removeFromCreateIterator(source, varName) {
|
||||||
var snippet = matchFunction(source, 'createIterator');
|
var snippet = matchFunction(source, 'createIterator');
|
||||||
if ( snippet) {
|
if (!snippet) {
|
||||||
// remove data object property assignment
|
return source;
|
||||||
var modified = snippet.replace(RegExp("^ *'" + varName + "': *" + varName + '.+\\n', 'm'), '');
|
|
||||||
source = source.replace(snippet, function() {
|
|
||||||
return modified;
|
|
||||||
});
|
|
||||||
|
|
||||||
// clip at the `factory` assignment
|
|
||||||
snippet = modified.match(/Function\([\s\S]+$/)[0];
|
|
||||||
|
|
||||||
modified = snippet
|
|
||||||
.replace(RegExp('\\b' + varName + '\\b,? *', 'g'), '')
|
|
||||||
.replace(/, *',/, "',")
|
|
||||||
.replace(/,\s*\)/, ')')
|
|
||||||
|
|
||||||
source = source.replace(snippet, function() {
|
|
||||||
return modified;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// remove data object property assignment
|
||||||
|
var modified = snippet.replace(RegExp("^ *'" + varName + "': *" + varName + '.+\\n', 'm'), '');
|
||||||
|
source = source.replace(snippet, function() {
|
||||||
|
return modified;
|
||||||
|
});
|
||||||
|
|
||||||
|
// clip at the `factory` assignment
|
||||||
|
snippet = modified.match(/Function\([\s\S]+$/)[0];
|
||||||
|
|
||||||
|
modified = snippet
|
||||||
|
.replace(RegExp('\\b' + varName + '\\b,? *', 'g'), '')
|
||||||
|
.replace(/, *',/, "',")
|
||||||
|
.replace(/,\s*\)/, ')')
|
||||||
|
|
||||||
|
source = source.replace(snippet, function() {
|
||||||
|
return modified;
|
||||||
|
});
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -969,25 +971,13 @@
|
|||||||
* @returns {String} Returns the modified source.
|
* @returns {String} Returns the modified source.
|
||||||
*/
|
*/
|
||||||
function removeFunction(source, funcName) {
|
function removeFunction(source, funcName) {
|
||||||
// remove function
|
var snippet;
|
||||||
var snippet = matchFunction(source, funcName);
|
|
||||||
if (snippet) {
|
|
||||||
if (funcName == 'runInContext') {
|
|
||||||
source = source.replace(snippet, function() {
|
|
||||||
return snippet
|
|
||||||
.replace(/^[\s\S]+?function runInContext[\s\S]+?context *= *context.+| *return lodash[\s\S]+$/g, '')
|
|
||||||
.replace(/^ {4}/gm, ' ');
|
|
||||||
});
|
|
||||||
|
|
||||||
source = source
|
// remove function
|
||||||
.replace(/context/g, 'window')
|
if (funcName == 'runInContext') {
|
||||||
.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var Array *=[\s\S]+?;\n/, '')
|
source = removeRunInContext(source, funcName);
|
||||||
.replace(/(return *|= *)_([;)])/g, '$1lodash$2')
|
} else if ((snippet = matchFunction(source, funcName))) {
|
||||||
.replace(/^ *var _ *=.+\n+/m, '');
|
source = source.replace(snippet, '');
|
||||||
}
|
|
||||||
else {
|
|
||||||
source = source.replace(snippet, '');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// grab the method assignments snippet
|
// grab the method assignments snippet
|
||||||
snippet = getMethodAssignments(source);
|
snippet = getMethodAssignments(source);
|
||||||
@@ -1016,15 +1006,13 @@
|
|||||||
* @returns {String} Returns the modified source.
|
* @returns {String} Returns the modified source.
|
||||||
*/
|
*/
|
||||||
function removeHasDontEnumBug(source) {
|
function removeHasDontEnumBug(source) {
|
||||||
|
source = removeVar(source, 'shadowedProps');
|
||||||
source = removeFromCreateIterator(source, 'hasDontEnumBug');
|
source = removeFromCreateIterator(source, 'hasDontEnumBug');
|
||||||
source = removeFromCreateIterator(source, 'shadowed');
|
source = removeFromCreateIterator(source, 'shadowedProps');
|
||||||
|
|
||||||
// remove `hasDontEnumBug` declaration and assignment
|
// remove `hasDontEnumBug` declaration and assignment
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug\b.*|.+?hasDontEnumBug *=.+/g, '');
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug\b.*|.+?hasDontEnumBug *=.+/g, '');
|
||||||
|
|
||||||
// remove `shadowed` variable
|
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var shadowed[\s\S]+?;\n/, '');
|
|
||||||
|
|
||||||
// remove `hasDontEnumBug` from `iteratorTemplate`
|
// remove `hasDontEnumBug` from `iteratorTemplate`
|
||||||
source = source.replace(getIteratorTemplate(source), function(match) {
|
source = source.replace(getIteratorTemplate(source), function(match) {
|
||||||
return match.replace(/(?: *\/\/.*\n)* *["']( *)<% *if *\(hasDontEnumBug[\s\S]+?["']\1<% *} *%>.+/, '');
|
return match.replace(/(?: *\/\/.*\n)* *["']( *)<% *if *\(hasDontEnumBug[\s\S]+?["']\1<% *} *%>.+/, '');
|
||||||
@@ -1063,6 +1051,22 @@
|
|||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes all `hasObjectSpliceBug` references from `source`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {String} source The source to process.
|
||||||
|
* @returns {String} Returns the modified source.
|
||||||
|
*/
|
||||||
|
function removeHasObjectSpliceBug(source) {
|
||||||
|
source = removeVar(source, 'hasObjectSpliceBug')
|
||||||
|
|
||||||
|
// remove `hasObjectSpliceBug` fix from the `Array` function mixins
|
||||||
|
source = source.replace(/(?:\s*\/\/.*)*\n( *)if *\(hasObjectSpliceBug[\s\S]+?(?:{\s*}|\n\1})/, '');
|
||||||
|
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the `_.isArguments` fallback from `source`.
|
* Removes the `_.isArguments` fallback from `source`.
|
||||||
*
|
*
|
||||||
@@ -1241,17 +1245,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all `hasObjectSpliceBug` references from `source`.
|
* Removes all `runInContext` references from `source`.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {String} source The source to process.
|
* @param {String} source The source to process.
|
||||||
* @returns {String} Returns the modified source.
|
* @returns {String} Returns the modified source.
|
||||||
*/
|
*/
|
||||||
function removeHasObjectSpliceBug(source) {
|
function removeRunInContext(source) {
|
||||||
source = removeVar(source, 'hasObjectSpliceBug')
|
source = removeVar(source, 'contextProps');
|
||||||
|
|
||||||
// remove `hasObjectSpliceBug` fix from the `Array` function mixins
|
// remove function scaffolding, leaving most of its content
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\n( *)if *\(hasObjectSpliceBug[\s\S]+?(?:{\s*}|\n\1})/, '');
|
source = source.replace(matchFunction(source, 'runInContext'), function(match) {
|
||||||
|
return match
|
||||||
|
.replace(/^[\s\S]+?function runInContext[\s\S]+?context *= *context.+| *return lodash[\s\S]+$/g, '')
|
||||||
|
.replace(/^ {4}/gm, ' ');
|
||||||
|
});
|
||||||
|
|
||||||
|
// cleanup adjusted source
|
||||||
|
source = source
|
||||||
|
.replace(/\bcontext\b/g, 'window')
|
||||||
|
.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var Array *=[\s\S]+?;\n/, '')
|
||||||
|
.replace(/(return *|= *)_([;)])/g, '$1lodash$2')
|
||||||
|
.replace(/^ *var _ *=.+\n+/m, '');
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
@@ -1281,8 +1296,8 @@
|
|||||||
* @returns {String} Returns the modified source.
|
* @returns {String} Returns the modified source.
|
||||||
*/
|
*/
|
||||||
function removeVar(source, varName) {
|
function removeVar(source, varName) {
|
||||||
// simplify `cloneableClasses`, `ctorByClass`, or `hasObjectSpliceBug`
|
// simplify complex variable assignments
|
||||||
if (/^(?:cloneableClasses|ctorByClass|hasObjectSpliceBug)$/.test(varName)) {
|
if (/^(?:cloneableClasses|contextProps|ctorByClass|hasObjectSpliceBug|shadowedProps)$/.test(varName)) {
|
||||||
source = source.replace(RegExp('(var ' + varName + ' *=)[\\s\\S]+?\\n\\n'), '$1=null;\n\n');
|
source = source.replace(RegExp('(var ' + varName + ' *=)[\\s\\S]+?\\n\\n'), '$1=null;\n\n');
|
||||||
}
|
}
|
||||||
source = source.replace(RegExp(
|
source = source.replace(RegExp(
|
||||||
@@ -1313,16 +1328,19 @@
|
|||||||
* @returns {String} Returns the modified source.
|
* @returns {String} Returns the modified source.
|
||||||
*/
|
*/
|
||||||
function replaceFunction(source, funcName, funcValue) {
|
function replaceFunction(source, funcName, funcValue) {
|
||||||
var match = matchFunction(source, funcName);
|
var snippet = matchFunction(source, funcName);
|
||||||
if (match) {
|
if (!snippet) {
|
||||||
// clip snippet after the JSDoc comment block
|
return source;
|
||||||
match = match.replace(/^\s*(?:\/\/.*|\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)\n/, '');
|
|
||||||
source = source.replace(match, function() {
|
|
||||||
return funcValue
|
|
||||||
.replace(RegExp('^' + getIndent(funcValue), 'gm'), getIndent(match))
|
|
||||||
.trimRight() + '\n';
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
// clip snippet after the JSDoc comment block
|
||||||
|
snippet = snippet.replace(/^\s*(?:\/\/.*|\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)\n/, '');
|
||||||
|
|
||||||
|
source = source.replace(snippet, function() {
|
||||||
|
return funcValue
|
||||||
|
.replace(RegExp('^' + getIndent(funcValue), 'gm'), getIndent(snippet))
|
||||||
|
.trimRight() + '\n';
|
||||||
|
});
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2136,13 +2154,13 @@
|
|||||||
// add `_.findWhere`
|
// add `_.findWhere`
|
||||||
source = source.replace(matchFunction(source, 'find'), function(match) {
|
source = source.replace(matchFunction(source, 'find'), function(match) {
|
||||||
var indent = getIndent(match);
|
var indent = getIndent(match);
|
||||||
return match + [
|
return match && (match + [
|
||||||
'',
|
'',
|
||||||
'function findWhere(object, properties) {',
|
'function findWhere(object, properties) {',
|
||||||
' return where(object, properties, true);',
|
' return where(object, properties, true);',
|
||||||
'}',
|
'}',
|
||||||
''
|
''
|
||||||
].join('\n' + indent);
|
].join('\n' + indent));
|
||||||
});
|
});
|
||||||
|
|
||||||
source = source.replace(getMethodAssignments(source), function(match) {
|
source = source.replace(getMethodAssignments(source), function(match) {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
'loop',
|
'loop',
|
||||||
'nonEnumArgs',
|
'nonEnumArgs',
|
||||||
'noCharByIndex',
|
'noCharByIndex',
|
||||||
'shadowed',
|
'shadowedProps',
|
||||||
'top',
|
'top',
|
||||||
'useHas'
|
'useHas'
|
||||||
];
|
];
|
||||||
@@ -58,20 +58,28 @@
|
|||||||
|
|
||||||
/** Used to protect the specified properties from getting minified */
|
/** Used to protect the specified properties from getting minified */
|
||||||
var propWhitelist = [
|
var propWhitelist = [
|
||||||
|
'Array',
|
||||||
|
'Boolean',
|
||||||
|
'Date',
|
||||||
|
'Function',
|
||||||
|
'Math',
|
||||||
|
'Number',
|
||||||
|
'Object',
|
||||||
|
'RegExp',
|
||||||
|
'String',
|
||||||
|
'VERSION',
|
||||||
'_',
|
'_',
|
||||||
'__wrapped__',
|
'__wrapped__',
|
||||||
'after',
|
'after',
|
||||||
'all',
|
'all',
|
||||||
'amd',
|
'amd',
|
||||||
'any',
|
'any',
|
||||||
'Array',
|
|
||||||
'assign',
|
'assign',
|
||||||
'at',
|
'at',
|
||||||
'attachEvent',
|
'attachEvent',
|
||||||
'bind',
|
'bind',
|
||||||
'bindAll',
|
'bindAll',
|
||||||
'bindKey',
|
'bindKey',
|
||||||
'Boolean',
|
|
||||||
'clearTimeout',
|
'clearTimeout',
|
||||||
'clone',
|
'clone',
|
||||||
'cloneDeep',
|
'cloneDeep',
|
||||||
@@ -81,7 +89,6 @@
|
|||||||
'contains',
|
'contains',
|
||||||
'countBy',
|
'countBy',
|
||||||
'criteria',
|
'criteria',
|
||||||
'Date',
|
|
||||||
'debounce',
|
'debounce',
|
||||||
'defaults',
|
'defaults',
|
||||||
'defer',
|
'defer',
|
||||||
@@ -105,14 +112,13 @@
|
|||||||
'forEach',
|
'forEach',
|
||||||
'forIn',
|
'forIn',
|
||||||
'forOwn',
|
'forOwn',
|
||||||
'Function',
|
|
||||||
'functions',
|
'functions',
|
||||||
'global',
|
'global',
|
||||||
'groupBy',
|
'groupBy',
|
||||||
'has',
|
'has',
|
||||||
'head',
|
'head',
|
||||||
'imports',
|
|
||||||
'identity',
|
'identity',
|
||||||
|
'imports',
|
||||||
'include',
|
'include',
|
||||||
'index',
|
'index',
|
||||||
'indexOf',
|
'indexOf',
|
||||||
@@ -145,7 +151,6 @@
|
|||||||
'last',
|
'last',
|
||||||
'lastIndexOf',
|
'lastIndexOf',
|
||||||
'map',
|
'map',
|
||||||
'Math',
|
|
||||||
'max',
|
'max',
|
||||||
'memoize',
|
'memoize',
|
||||||
'merge',
|
'merge',
|
||||||
@@ -153,11 +158,9 @@
|
|||||||
'min',
|
'min',
|
||||||
'mixin',
|
'mixin',
|
||||||
'noConflict',
|
'noConflict',
|
||||||
'Object',
|
|
||||||
'object',
|
'object',
|
||||||
'omit',
|
'omit',
|
||||||
'once',
|
'once',
|
||||||
'Number',
|
|
||||||
'pairs',
|
'pairs',
|
||||||
'parseInt',
|
'parseInt',
|
||||||
'partial',
|
'partial',
|
||||||
@@ -168,7 +171,6 @@
|
|||||||
'range',
|
'range',
|
||||||
'reduce',
|
'reduce',
|
||||||
'reduceRight',
|
'reduceRight',
|
||||||
'RegExp',
|
|
||||||
'reject',
|
'reject',
|
||||||
'rest',
|
'rest',
|
||||||
'result',
|
'result',
|
||||||
@@ -182,7 +184,6 @@
|
|||||||
'sortBy',
|
'sortBy',
|
||||||
'sortedIndex',
|
'sortedIndex',
|
||||||
'source',
|
'source',
|
||||||
'String',
|
|
||||||
'tail',
|
'tail',
|
||||||
'take',
|
'take',
|
||||||
'tap',
|
'tap',
|
||||||
@@ -199,7 +200,6 @@
|
|||||||
'value',
|
'value',
|
||||||
'values',
|
'values',
|
||||||
'variable',
|
'variable',
|
||||||
'VERSION',
|
|
||||||
'where',
|
'where',
|
||||||
'without',
|
'without',
|
||||||
'wrap',
|
'wrap',
|
||||||
|
|||||||
Reference in New Issue
Block a user