mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 11:57:49 +00:00
Move more code to be removed before the call to buildModule.
Former-commit-id: 255ba4bf6e65d61378226ba1c13708619ca68941
This commit is contained in:
71
build.js
71
build.js
@@ -1499,7 +1499,7 @@
|
|||||||
function matchProp(source, propName, leadingComments) {
|
function matchProp(source, propName, leadingComments) {
|
||||||
var result = source.match(RegExp(
|
var result = source.match(RegExp(
|
||||||
(leadingComments ? multilineComment : '\\n') +
|
(leadingComments ? multilineComment : '\\n') +
|
||||||
'(?: *|.*?=\\s*)lodash\\._?' + propName + '\\s*=[\\s\\S]+?' +
|
'(?: {2}var ' + propName + '\\b.+|(?: *|.*?=\\s*)lodash\\._?' + propName + '\\s*)=[\\s\\S]+?' +
|
||||||
'(?:\\(function[\\s\\S]+?\\([^)]*\\)\\);\\n(?=\\n)|' +
|
'(?:\\(function[\\s\\S]+?\\([^)]*\\)\\);\\n(?=\\n)|' +
|
||||||
'[;}]\\n(?=\\n(?!\\s*\\(func)))'
|
'[;}]\\n(?=\\n(?!\\s*\\(func)))'
|
||||||
));
|
));
|
||||||
@@ -1832,6 +1832,13 @@
|
|||||||
// replace `new lodashWrapper` with `new lodash`
|
// replace `new lodashWrapper` with `new lodash`
|
||||||
source = source.replace(/\bnew lodashWrapper\b/g, 'new lodash');
|
source = source.replace(/\bnew lodashWrapper\b/g, 'new lodash');
|
||||||
|
|
||||||
|
// remove `lodashWrapper` from `_.mixin`
|
||||||
|
source = source.replace(matchFunction(source, 'mixin'), function(match) {
|
||||||
|
return match
|
||||||
|
.replace(/!source\s*\|\|\s*/g, '')
|
||||||
|
.replace(/(?:\s*\/\/.*)*\n( *)if *\(!source[\s\S]+?\n\1}/, '');
|
||||||
|
});
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2198,7 +2205,7 @@
|
|||||||
* @returns {String} Returns the modified source.
|
* @returns {String} Returns the modified source.
|
||||||
*/
|
*/
|
||||||
function removeSupportProp(source, propName) {
|
function removeSupportProp(source, propName) {
|
||||||
return source.replace(matchVar(source, 'support'), function(match) {
|
return source.replace(matchProp(source, 'support'), function(match) {
|
||||||
return match.replace(RegExp(
|
return match.replace(RegExp(
|
||||||
multilineComment +
|
multilineComment +
|
||||||
// match a `try` block
|
// match a `try` block
|
||||||
@@ -2940,7 +2947,7 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (isModularize) {
|
if (isModularize) {
|
||||||
result = _.difference(result, getNamesByCategory('Chaining'), ['runInContext']);
|
_.pull(result, 'runInContext');
|
||||||
}
|
}
|
||||||
return getDependencies(result, funcDepMap);
|
return getDependencies(result, funcDepMap);
|
||||||
}());
|
}());
|
||||||
@@ -3949,6 +3956,36 @@
|
|||||||
}, match);
|
}, match);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (isModularize) {
|
||||||
|
source = removeAssignments(source);
|
||||||
|
source = removeGetIndexOf(source);
|
||||||
|
|
||||||
|
// replace the `lodash.templateSettings` property assignment with a variable assignment
|
||||||
|
source = source.replace(/\b(lodash\.)(?=templateSettings *=)/, 'var ');
|
||||||
|
|
||||||
|
// remove the `lodash` namespace from properties
|
||||||
|
source = source.replace(/\blodash\.(?!com|prototype)(\w+)\b(?!\s*=)/g, '$1');
|
||||||
|
|
||||||
|
// remove all horizontal rule comment separators
|
||||||
|
source = source.replace(/^ *\/\*-+\*\/\n/gm, '');
|
||||||
|
|
||||||
|
// remove debug sourceURL use in `_.template`
|
||||||
|
source = source.replace(matchFunction(source, 'template'), function(match) {
|
||||||
|
return match.replace(/(?:\s*\/\/.*\n)* *var sourceURL[^;]+;|\+ *sourceURL/g, '');
|
||||||
|
});
|
||||||
|
|
||||||
|
// replace `_` use in `_.templateSettings.imports`
|
||||||
|
source = source.replace(matchProp(source, 'templateSettings'), function(match) {
|
||||||
|
return match.replace(/(:\s*)lodash\b/, "$1{ 'escape': escape }");
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove function aliases
|
||||||
|
_.each(buildFuncs, function(funcName) {
|
||||||
|
_.each(getAliases(funcName, funcDepMap), function(alias) {
|
||||||
|
source = removeFunction(source, alias);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------*/
|
||||||
@@ -4149,7 +4186,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// remove code used to resolve unneeded `support` properties
|
// remove code used to resolve unneeded `support` properties
|
||||||
source = source.replace(matchVar(source, 'support'), function(match) {
|
source = source.replace(matchProp(source, 'support'), function(match) {
|
||||||
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;
|
||||||
|
|
||||||
@@ -4213,38 +4250,12 @@
|
|||||||
if (isExcluded('lodash')) {
|
if (isExcluded('lodash')) {
|
||||||
source = removeFunction(source, 'lodash');
|
source = removeFunction(source, 'lodash');
|
||||||
}
|
}
|
||||||
// replace the `lodash.templateSettings` property assignment with a variable assignment
|
|
||||||
source = source.replace(/\b(lodash\.)(?=templateSettings *=)/, 'var ');
|
|
||||||
|
|
||||||
// remove the `lodash` namespace from properties
|
|
||||||
source = source.replace(/\blodash\.(?!com)(\w+)\b(?!\s*=)/g, '$1');
|
|
||||||
|
|
||||||
// remove all horizontal rule comment separators
|
|
||||||
source = source.replace(/^ *\/\*-+\*\/\n/gm, '');
|
|
||||||
|
|
||||||
// remove debug sourceURL use in `_.template`
|
|
||||||
source = source.replace(matchFunction(source, 'template'), function(match) {
|
|
||||||
return match.replace(/(?:\s*\/\/.*\n)* *var sourceURL[^;]+;|\+ *sourceURL/g, '');
|
|
||||||
});
|
|
||||||
|
|
||||||
// replace `_` use in `_.templateSettings.imports`
|
|
||||||
source = source.replace(matchVar(source, 'templateSettings'), function(match) {
|
|
||||||
return match.replace(/(:\s*)lodash\b/, "$1{ 'escape': escape }");
|
|
||||||
});
|
|
||||||
|
|
||||||
// remove unneeded variable dependencies
|
// remove unneeded variable dependencies
|
||||||
_.each(varDependencies, function(varName) {
|
_.each(varDependencies, function(varName) {
|
||||||
if (!_.contains(includeVars, varName)) {
|
if (!_.contains(includeVars, varName)) {
|
||||||
source = removeVar(source, varName);
|
source = removeVar(source, varName);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove function aliases
|
|
||||||
_.each(buildFuncs, function(funcName) {
|
|
||||||
_.each(getAliases(funcName, funcDepMap), function(alias) {
|
|
||||||
source = removeFunction(source, alias);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else if (isUnderscore) {
|
else if (isUnderscore) {
|
||||||
// unexpose `lodash.support`
|
// unexpose `lodash.support`
|
||||||
|
|||||||
Reference in New Issue
Block a user