mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Add complexVars array, correct removeStrings, and cleanup isVarUsed in build.js.
Former-commit-id: 4d2c65fbad7659fe54c76127b9e9c0bb5731cf35
This commit is contained in:
87
build.js
87
build.js
@@ -422,23 +422,15 @@
|
|||||||
'without'
|
'without'
|
||||||
];
|
];
|
||||||
|
|
||||||
/** List of Lo-Dash only methods */
|
/** List of variables with complex assignments */
|
||||||
var lodashOnlyMethods = [
|
var complexVars = [
|
||||||
'at',
|
'cloneableClasses',
|
||||||
'bindKey',
|
'contextProps',
|
||||||
'cloneDeep',
|
'ctorByClass',
|
||||||
'createCallback',
|
'freeGlobal',
|
||||||
'findIndex',
|
'nonEnumProps',
|
||||||
'findKey',
|
'shadowedProps',
|
||||||
'forIn',
|
'whitespace'
|
||||||
'forOwn',
|
|
||||||
'isPlainObject',
|
|
||||||
'merge',
|
|
||||||
'parseInt',
|
|
||||||
'partialRight',
|
|
||||||
'runInContext',
|
|
||||||
'transform',
|
|
||||||
'unzip'
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/** List of ways to export the `lodash` function */
|
/** List of ways to export the `lodash` function */
|
||||||
@@ -464,6 +456,25 @@
|
|||||||
'useKeys'
|
'useKeys'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** List of Lo-Dash only methods */
|
||||||
|
var lodashOnlyMethods = [
|
||||||
|
'at',
|
||||||
|
'bindKey',
|
||||||
|
'cloneDeep',
|
||||||
|
'createCallback',
|
||||||
|
'findIndex',
|
||||||
|
'findKey',
|
||||||
|
'forIn',
|
||||||
|
'forOwn',
|
||||||
|
'isPlainObject',
|
||||||
|
'merge',
|
||||||
|
'parseInt',
|
||||||
|
'partialRight',
|
||||||
|
'runInContext',
|
||||||
|
'transform',
|
||||||
|
'unzip'
|
||||||
|
];
|
||||||
|
|
||||||
/** List of private methods */
|
/** List of private methods */
|
||||||
var privateMethods = [
|
var privateMethods = [
|
||||||
'basicEach',
|
'basicEach',
|
||||||
@@ -1179,7 +1190,7 @@
|
|||||||
var result = source.match(RegExp(
|
var result = source.match(RegExp(
|
||||||
multilineComment +
|
multilineComment +
|
||||||
'( *)var support *=[\\s\\S]+?\n\\1}\\(1\\)\\);\\n'
|
'( *)var support *=[\\s\\S]+?\n\\1}\\(1\\)\\);\\n'
|
||||||
, 'm'));
|
));
|
||||||
|
|
||||||
return result ? result[0] : '';
|
return result ? result[0] : '';
|
||||||
}
|
}
|
||||||
@@ -1222,9 +1233,11 @@
|
|||||||
indentB = isShallow ? ' {6}' : ' {6,8}';
|
indentB = isShallow ? ' {6}' : ' {6,8}';
|
||||||
|
|
||||||
var match = RegExp(
|
var match = RegExp(
|
||||||
'^(' + indentA + ')var ' + varName + ' *(?:|= *(?:.+?(?:|&&\\n[^;]+)|(?:\\w+\\(|[{[(]\\n)[\\s\\S]+?\\n\\1[^\\n ]+?));\\n|' +
|
(varName != 'freeGlobal' && _.contains(complexVars, varName))
|
||||||
'^' + indentA + 'var ' + varName + ' *=.+?,\\n(?= *\\w+ *=)|' +
|
? '^' + indentA + 'var ' + varName + ' *=[\\s\\S]+?(?:\\(function[\\s\\S]+?\\(\\)\\);\\n(?=\\n)|[;}]\\n(?=\\n(?!\\s*\\(func)))'
|
||||||
'^' + indentB + varName + ' *=.+?[,;]\\n'
|
: '^(' + indentA + ')var ' + varName + ' *(?:|= *(?:.+?(?:|&&\\n[^;]+)|(?:\\w+\\(|[{[(]\\n)[\\s\\S]+?\\n\\1[^\\n ]+?));\\n|' +
|
||||||
|
'^' + indentA + 'var ' + varName + ' *=.+?,\\n(?= *\\w+ *=)|' +
|
||||||
|
'^' + indentB + varName + ' *=.+?[,;]\\n'
|
||||||
, 'm')
|
, 'm')
|
||||||
.exec(source);
|
.exec(source);
|
||||||
|
|
||||||
@@ -1540,20 +1553,6 @@
|
|||||||
return source.replace(getMethodAssignments(source), '');
|
return source.replace(getMethodAssignments(source), '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes `nonEnumProps` array assignments from `source`.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {String} source The source to process.
|
|
||||||
* @returns {String} Returns the modified source.
|
|
||||||
*/
|
|
||||||
function removeNonEnumProps(source) {
|
|
||||||
// remove nested `nonEnumProps` assignments
|
|
||||||
source = removeVar(source, 'nonEnumProps');
|
|
||||||
source = source.replace(/^ *\(function.+?\n *var length\b[\s\S]+?shadowedProps[\s\S]+?}\(\)\);\n/m, '');
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all pseudo private properties from `source`. If a `propName` is
|
* Removes all pseudo private properties from `source`. If a `propName` is
|
||||||
* specified, only the specified property is removed.
|
* specified, only the specified property is removed.
|
||||||
@@ -1624,7 +1623,7 @@
|
|||||||
* @returns {String} Returns the modified source.
|
* @returns {String} Returns the modified source.
|
||||||
*/
|
*/
|
||||||
function removeStrings(source) {
|
function removeStrings(source) {
|
||||||
return source.replace(/(['"])[^\1\n\\]*?(?:\\.[^\1\n\\]*?)*\1/g, '');
|
return source.replace(/(["'])(?:(?!\1)[^\n\\]|\\.)*\1/g, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1907,8 +1906,12 @@
|
|||||||
return removeSupport(source);
|
return removeSupport(source);
|
||||||
}
|
}
|
||||||
// simplify complex variable assignments
|
// simplify complex variable assignments
|
||||||
if (/^(?:cloneableClasses|contextProps|ctorByClass|freeGlobal|nonEnumProps|shadowedProps|whitespace)$/.test(varName)) {
|
if (_.contains(complexVars, varName)) {
|
||||||
source = source.replace(RegExp('(var ' + varName + ') *=[\\s\\S]+?[;}]\\n\\n'), '$1 = null;\n\n');
|
source = source.replace(RegExp(
|
||||||
|
'^( *var ' + varName + ') *=[\\s\\S]+?' +
|
||||||
|
'(?:\\(function[\\s\\S]+?\\(\\)\\);(?=\\n\\n)|' +
|
||||||
|
'[;}](?=\\n\\n(?!\\s*\\(func)))'
|
||||||
|
, 'm'), '$1 = null;')
|
||||||
}
|
}
|
||||||
|
|
||||||
source = removeFunction(source, varName);
|
source = removeFunction(source, varName);
|
||||||
@@ -3644,14 +3647,6 @@
|
|||||||
|
|
||||||
// modify/remove references to removed methods/variables
|
// modify/remove references to removed methods/variables
|
||||||
if (!isTemplate) {
|
if (!isTemplate) {
|
||||||
if (isExcluded('clone') ||
|
|
||||||
isUnderscore && (!isLodashMethod('clone') && !isLodashMethod('cloneDeep'))) {
|
|
||||||
source = removeVar(source, 'cloneableClasses');
|
|
||||||
source = removeVar(source, 'ctorByClass');
|
|
||||||
}
|
|
||||||
if (isExcluded('createIterator')) {
|
|
||||||
source = removeNonEnumProps(source);
|
|
||||||
}
|
|
||||||
if (isExcluded('invert')) {
|
if (isExcluded('invert')) {
|
||||||
source = replaceVar(source, 'htmlUnescapes', "{'&':'&','<':'<','>':'>','"':'\"',''':\"'\"}");
|
source = replaceVar(source, 'htmlUnescapes', "{'&':'&','<':'<','>':'>','"':'\"',''':\"'\"}");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user