mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 10:17:48 +00:00
Initial lodash template=… build support.
Former-commit-id: 9d13021463380556a997cb53f5ae89eb22a7b98b
This commit is contained in:
726
build.js
726
build.js
@@ -67,7 +67,7 @@
|
|||||||
'bind': ['isFunction'],
|
'bind': ['isFunction'],
|
||||||
'bindAll': ['bind', 'isFunction'],
|
'bindAll': ['bind', 'isFunction'],
|
||||||
'chain': ['mixin'],
|
'chain': ['mixin'],
|
||||||
'clone': ['extend', 'forIn', 'forOwn', 'isArguments', 'isFunction'],
|
'clone': ['extend', 'forOwn', 'isArguments', 'isPlainObject'],
|
||||||
'compact': [],
|
'compact': [],
|
||||||
'compose': [],
|
'compose': [],
|
||||||
'contains': [],
|
'contains': [],
|
||||||
@@ -109,6 +109,7 @@
|
|||||||
'isNull': [],
|
'isNull': [],
|
||||||
'isNumber': [],
|
'isNumber': [],
|
||||||
'isObject': [],
|
'isObject': [],
|
||||||
|
'isPlainObject': ['forIn', 'isArguments', 'isFunction'],
|
||||||
'isRegExp': [],
|
'isRegExp': [],
|
||||||
'isString': [],
|
'isString': [],
|
||||||
'isUndefined': [],
|
'isUndefined': [],
|
||||||
@@ -119,7 +120,7 @@
|
|||||||
'map': ['identity'],
|
'map': ['identity'],
|
||||||
'max': [],
|
'max': [],
|
||||||
'memoize': [],
|
'memoize': [],
|
||||||
'merge': ['isArguments', 'isArray', 'forIn'],
|
'merge': ['isArray', 'isPlainObject'],
|
||||||
'min': [],
|
'min': [],
|
||||||
'mixin': ['forEach', 'functions'],
|
'mixin': ['forEach', 'functions'],
|
||||||
'noConflict': [],
|
'noConflict': [],
|
||||||
@@ -236,6 +237,7 @@
|
|||||||
var underscoreMethods = _.without.apply(_, [allMethods].concat([
|
var underscoreMethods = _.without.apply(_, [allMethods].concat([
|
||||||
'forIn',
|
'forIn',
|
||||||
'forOwn',
|
'forOwn',
|
||||||
|
'isPlainObject',
|
||||||
'lateBind',
|
'lateBind',
|
||||||
'merge',
|
'merge',
|
||||||
'partial'
|
'partial'
|
||||||
@@ -251,6 +253,42 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a debug and minified build, executing the `callback` for each.
|
||||||
|
* The `callback` is invoked with 2 arguments; (filepath, source)
|
||||||
|
*
|
||||||
|
* @param {Array} options The options array.
|
||||||
|
* @param {Function} callback The function called per build.
|
||||||
|
*/
|
||||||
|
function buildTemplate(templatePattern, templateSettings) {
|
||||||
|
var directory = path.dirname(templatePattern);
|
||||||
|
|
||||||
|
var pattern = RegExp(
|
||||||
|
path.basename(templatePattern)
|
||||||
|
.replace(/[.+?^=!:${}()|[\]\/\\]/g, '\\$&')
|
||||||
|
.replace(/\*/g, '.*?') + '$'
|
||||||
|
);
|
||||||
|
|
||||||
|
var source = [
|
||||||
|
';(function() {',
|
||||||
|
' var templates = _.templates || (_.templates = {});'
|
||||||
|
];
|
||||||
|
|
||||||
|
fs.readdirSync(directory).forEach(function(filename) {
|
||||||
|
var filepath = path.join(directory, filename);
|
||||||
|
if (pattern.test(filename)) {
|
||||||
|
var text = fs.readFileSync(filepath, 'utf8'),
|
||||||
|
precompiled = getFunctionSource(_.template(text, null, templateSettings)),
|
||||||
|
prop = filename.replace(/\..*$/, '');
|
||||||
|
|
||||||
|
source.push(' templates["' + prop + '"] = ' + precompiled + ';');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
source.push('}());');
|
||||||
|
return source.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes unnecessary comments, whitespace, and pseudo private properties.
|
* Removes unnecessary comments, whitespace, and pseudo private properties.
|
||||||
*
|
*
|
||||||
@@ -294,9 +332,10 @@
|
|||||||
' lodash exports=... Comma separated names of ways to export the `LoDash` function',
|
' lodash exports=... Comma separated names of ways to export the `LoDash` function',
|
||||||
' (i.e. “amd”, “commonjs”, “global”, “node”, and “none”)',
|
' (i.e. “amd”, “commonjs”, “global”, “node”, and “none”)',
|
||||||
' lodash iife=... Code to replace the immediately-invoked function expression that wraps Lo-Dash',
|
' lodash iife=... Code to replace the immediately-invoked function expression that wraps Lo-Dash',
|
||||||
' (e.g. “!function(window,undefined){%output%}(this)”)',
|
' (e.g. `lodash iife="!function(window,undefined){%output%}(this)"`)',
|
||||||
|
'',
|
||||||
' lodash template=... The file path pattern used for matching template files to compile',
|
' lodash template=... The file path pattern used for matching template files to compile',
|
||||||
' (e.g. `lodash template=path/to/templates/*.tmpl`)',
|
' (e.g. `lodash template=./*.jst`)',
|
||||||
'',
|
'',
|
||||||
' All arguments, except `legacy` with `csp` or `mobile`, may be combined.',
|
' All arguments, except `legacy` with `csp` or `mobile`, may be combined.',
|
||||||
' Unless specified by `-o` or `--output`, all files created are saved to the current working directory.',
|
' Unless specified by `-o` or `--output`, all files created are saved to the current working directory.',
|
||||||
@@ -304,7 +343,9 @@
|
|||||||
' Options:',
|
' Options:',
|
||||||
'',
|
'',
|
||||||
' -c, --stdout Write output to standard output',
|
' -c, --stdout Write output to standard output',
|
||||||
|
' -d, --debug Write only the debug output',
|
||||||
' -h, --help Display help information',
|
' -h, --help Display help information',
|
||||||
|
' -m, --minify Write only the minified output',
|
||||||
' -o, --output Write output to a given path/filename',
|
' -o, --output Write output to a given path/filename',
|
||||||
' -s, --silent Skip status updates normally logged to the console',
|
' -s, --silent Skip status updates normally logged to the console',
|
||||||
' -V, --version Output current version of Lo-Dash',
|
' -V, --version Output current version of Lo-Dash',
|
||||||
@@ -734,7 +775,7 @@
|
|||||||
* Creates a debug and minified build, executing the `callback` for each.
|
* Creates a debug and minified build, executing the `callback` for each.
|
||||||
* The `callback` is invoked with 2 arguments; (filepath, source)
|
* The `callback` is invoked with 2 arguments; (filepath, source)
|
||||||
*
|
*
|
||||||
* @param {Array} options The options array.
|
* @param {Array} options The build options array.
|
||||||
* @param {Function} callback The function called per build.
|
* @param {Function} callback The function called per build.
|
||||||
*/
|
*/
|
||||||
function build(options, callback) {
|
function build(options, callback) {
|
||||||
@@ -746,7 +787,7 @@
|
|||||||
// used to report invalid command-line arguments
|
// used to report invalid command-line arguments
|
||||||
var invalidArgs = _.reject(options.slice(options[0] == 'node' ? 2 : 0), function(value, index, options) {
|
var invalidArgs = _.reject(options.slice(options[0] == 'node' ? 2 : 0), function(value, index, options) {
|
||||||
if (/^(?:-o|--output)$/.test(options[index - 1]) ||
|
if (/^(?:-o|--output)$/.test(options[index - 1]) ||
|
||||||
/^(?:category|exclude|exports|iife|include|minus|plus|template)=.*$/.test(value)) {
|
/^(?:category|exclude|exports|iife|include|minus|plus|settings|template)=.*$/.test(value)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return [
|
return [
|
||||||
@@ -757,7 +798,9 @@
|
|||||||
'strict',
|
'strict',
|
||||||
'underscore',
|
'underscore',
|
||||||
'-c', '--stdout',
|
'-c', '--stdout',
|
||||||
|
'-d', '--debug',
|
||||||
'-h', '--help',
|
'-h', '--help',
|
||||||
|
'-m', '--minify',
|
||||||
'-o', '--output',
|
'-o', '--output',
|
||||||
'-s', '--silent',
|
'-s', '--silent',
|
||||||
'-V', '--version'
|
'-V', '--version'
|
||||||
@@ -798,7 +841,8 @@
|
|||||||
|
|
||||||
// used to specify a custom IIFE to wrap Lo-Dash
|
// used to specify a custom IIFE to wrap Lo-Dash
|
||||||
var iife = options.reduce(function(result, value) {
|
var iife = options.reduce(function(result, value) {
|
||||||
return result || (result = value.match(/iife=(.*)/)) && result[1];
|
var match = value.match(/iife=(.*)/);
|
||||||
|
return match ? match[1] : result;
|
||||||
}, null);
|
}, null);
|
||||||
|
|
||||||
// flag used to specify a Backbone build
|
// flag used to specify a Backbone build
|
||||||
@@ -807,12 +851,18 @@
|
|||||||
// flag used to specify a Content Security Policy build
|
// flag used to specify a Content Security Policy build
|
||||||
var isCSP = options.indexOf('csp') > -1 || options.indexOf('CSP') > -1;
|
var isCSP = options.indexOf('csp') > -1 || options.indexOf('CSP') > -1;
|
||||||
|
|
||||||
|
// flag used to specify only creating the debug build
|
||||||
|
var isDebug = options.indexOf('-d') > -1 || options.indexOf('--debug') > -1;
|
||||||
|
|
||||||
// flag used to specify a legacy build
|
// flag used to specify a legacy build
|
||||||
var isLegacy = options.indexOf('legacy') > -1;
|
var isLegacy = options.indexOf('legacy') > -1;
|
||||||
|
|
||||||
// flag used to specify an Underscore build
|
// flag used to specify an Underscore build
|
||||||
var isUnderscore = options.indexOf('underscore') > -1;
|
var isUnderscore = options.indexOf('underscore') > -1;
|
||||||
|
|
||||||
|
// flag used to specify only creating the minified build
|
||||||
|
var isMinify = !isDebug && options.indexOf('-m') > -1 || options.indexOf('--minify')> -1;
|
||||||
|
|
||||||
// flag used to specify a mobile build
|
// flag used to specify a mobile build
|
||||||
var isMobile = !isLegacy && (isCSP || isUnderscore || options.indexOf('mobile') > -1);
|
var isMobile = !isLegacy && (isCSP || isUnderscore || options.indexOf('mobile') > -1);
|
||||||
|
|
||||||
@@ -836,9 +886,32 @@
|
|||||||
|
|
||||||
// used to specify the output path for builds
|
// used to specify the output path for builds
|
||||||
var outputPath = options.reduce(function(result, value, index) {
|
var outputPath = options.reduce(function(result, value, index) {
|
||||||
return result || (/^(?:-o|--output)$/.test(value) ? options[index + 1] : result);
|
if (/-o|--output/.test(value)) {
|
||||||
|
result = options[index + 1];
|
||||||
|
result = path.join(fs.realpathSync(path.dirname(result)), path.basename(result));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}, '');
|
}, '');
|
||||||
|
|
||||||
|
// used to match external template files to pre-compile
|
||||||
|
var templatePattern = options.reduce(function(result, value) {
|
||||||
|
var match = value.match(/template=(.+)$/);
|
||||||
|
return match
|
||||||
|
? path.join(fs.realpathSync(path.dirname(match[1])), path.basename(match[1]))
|
||||||
|
: result;
|
||||||
|
}, '');
|
||||||
|
|
||||||
|
// used when pre-compiling template files
|
||||||
|
var templateSettings = options.reduce(function(result, value) {
|
||||||
|
var match = value.match(/settings=(.+)$/);
|
||||||
|
return match
|
||||||
|
? JSON.parse(match[1])
|
||||||
|
: result;
|
||||||
|
}, _.clone(_.templateSettings));
|
||||||
|
|
||||||
|
// flag used to specify a template build
|
||||||
|
var isTemplate = !!templatePattern;
|
||||||
|
|
||||||
// the lodash.js source
|
// the lodash.js source
|
||||||
var source = fs.readFileSync(path.join(__dirname, 'lodash.js'), 'utf8');
|
var source = fs.readFileSync(path.join(__dirname, 'lodash.js'), 'utf8');
|
||||||
|
|
||||||
@@ -847,65 +920,68 @@
|
|||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// collections of method names
|
// names of methods to include in the build
|
||||||
var buildMethods;
|
var buildMethods = !isTemplate && (function() {
|
||||||
|
var result;
|
||||||
|
|
||||||
var minusMethods = options.reduce(function(result, value) {
|
var minusMethods = options.reduce(function(accumulator, value) {
|
||||||
return /exclude|minus/.test(value)
|
return /exclude|minus/.test(value)
|
||||||
? _.union(result, optionToMethodsArray(source, value))
|
? _.union(accumulator, optionToMethodsArray(source, value))
|
||||||
: result;
|
: accumulator;
|
||||||
}, []);
|
|
||||||
|
|
||||||
var plusMethods = options.reduce(function(result, value) {
|
|
||||||
return /plus/.test(value)
|
|
||||||
? _.union(result, optionToMethodsArray(source, value))
|
|
||||||
: result;
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// add method names explicitly
|
|
||||||
options.some(function(value) {
|
|
||||||
return /include/.test(value) &&
|
|
||||||
(buildMethods = getDependencies(optionToMethodsArray(source, value)));
|
|
||||||
});
|
|
||||||
|
|
||||||
// add method names required by Backbone and Underscore builds
|
|
||||||
if (isBackbone && !buildMethods) {
|
|
||||||
buildMethods = getDependencies(backboneDependencies);
|
|
||||||
}
|
|
||||||
if (isUnderscore && !buildMethods) {
|
|
||||||
buildMethods = getDependencies(underscoreMethods);
|
|
||||||
}
|
|
||||||
|
|
||||||
// add method names by category
|
|
||||||
options.some(function(value) {
|
|
||||||
if (!/category/.test(value)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// resolve method names belonging to each category (case-insensitive)
|
|
||||||
var methodNames = optionToArray(value).reduce(function(result, category) {
|
|
||||||
var capitalized = category[0].toUpperCase() + category.toLowerCase().slice(1);
|
|
||||||
return result.concat(getMethodsByCategory(source, capitalized));
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (buildMethods = _.union(buildMethods || [], getDependencies(methodNames)));
|
var plusMethods = options.reduce(function(accumulator, value) {
|
||||||
});
|
return /plus/.test(value)
|
||||||
|
? _.union(accumulator, optionToMethodsArray(source, value))
|
||||||
|
: accumulator;
|
||||||
|
}, []);
|
||||||
|
|
||||||
// init `buildMethods` if it hasn't been inited
|
// add method names explicitly
|
||||||
if (!buildMethods) {
|
options.some(function(value) {
|
||||||
buildMethods = allMethods.slice();
|
return /include/.test(value) &&
|
||||||
}
|
(result = getDependencies(optionToMethodsArray(source, value)));
|
||||||
|
});
|
||||||
|
|
||||||
if (plusMethods.length) {
|
// add method names required by Backbone and Underscore builds
|
||||||
buildMethods = _.union(buildMethods, getDependencies(plusMethods));
|
if (isBackbone && !result) {
|
||||||
}
|
result = getDependencies(backboneDependencies);
|
||||||
if (minusMethods.length) {
|
}
|
||||||
buildMethods = _.without.apply(_, [buildMethods].concat(minusMethods, getDependants(buildMethods)));
|
if (isUnderscore && !result) {
|
||||||
}
|
result = getDependencies(underscoreMethods);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add method names by category
|
||||||
|
options.some(function(value) {
|
||||||
|
if (!/category/.test(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// resolve method names belonging to each category (case-insensitive)
|
||||||
|
var methodNames = optionToArray(value).reduce(function(accumulator, category) {
|
||||||
|
var capitalized = category[0].toUpperCase() + category.toLowerCase().slice(1);
|
||||||
|
return accumulator.concat(getMethodsByCategory(source, capitalized));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (result = _.union(result || [], getDependencies(methodNames)));
|
||||||
|
});
|
||||||
|
|
||||||
|
// init `result` if it hasn't been inited
|
||||||
|
if (!result) {
|
||||||
|
result = allMethods.slice();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plusMethods.length) {
|
||||||
|
result = _.union(result, getDependencies(plusMethods));
|
||||||
|
}
|
||||||
|
if (minusMethods.length) {
|
||||||
|
result = _.without.apply(_, [result].concat(minusMethods, getDependants(result)));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}());
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// load customized Lo-Dash module
|
// load customized Lo-Dash module
|
||||||
var lodash = (function() {
|
var lodash = !isTemplate && (function() {
|
||||||
var context = vm.createContext({
|
var context = vm.createContext({
|
||||||
'clearTimeout': clearTimeout,
|
'clearTimeout': clearTimeout,
|
||||||
'setTimeout': setTimeout
|
'setTimeout': setTimeout
|
||||||
@@ -980,156 +1056,191 @@
|
|||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// simplify template snippets by removing unnecessary brackets
|
if (isTemplate) {
|
||||||
source = source.replace(
|
source = buildTemplate(templatePattern, templateSettings);
|
||||||
RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *([,\\n])", 'g'), "$1'$2"
|
}
|
||||||
);
|
else {
|
||||||
|
// simplify template snippets by removing unnecessary brackets
|
||||||
|
source = source.replace(
|
||||||
|
RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *([,\\n])", 'g'), "$1'$2"
|
||||||
|
);
|
||||||
|
|
||||||
source = source.replace(
|
source = source.replace(
|
||||||
RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *\\+", 'g'), "$1;\\n'+"
|
RegExp("{(\\\\n' *\\+\\s*.*?\\+\\n\\s*' *)}(?:\\\\n)?' *\\+", 'g'), "$1;\\n'+"
|
||||||
);
|
);
|
||||||
|
|
||||||
// remove methods from the build
|
// remove methods from the build
|
||||||
allMethods.forEach(function(otherName) {
|
allMethods.forEach(function(otherName) {
|
||||||
if (!_.contains(buildMethods, otherName)) {
|
if (!_.contains(buildMethods, otherName)) {
|
||||||
source = removeFunction(source, otherName);
|
source = removeFunction(source, otherName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove `isArguments` fallback before `isArguments` is transformed by
|
||||||
|
// other parts of the build process
|
||||||
|
if (isRemoved(source, 'isArguments')) {
|
||||||
|
source = removeIsArgumentsFallback(source);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// remove `isArguments` fallback before `isArguments` is transformed by
|
/*----------------------------------------------------------------------*/
|
||||||
// other parts of the build process
|
|
||||||
if (isRemoved(source, 'isArguments')) {
|
if (isLegacy) {
|
||||||
source = removeIsArgumentsFallback(source);
|
_.each(['isBindFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'], function(varName) {
|
||||||
|
source = removeVar(source, varName);
|
||||||
|
});
|
||||||
|
|
||||||
|
_.each(['bind', 'isArray'], function(methodName) {
|
||||||
|
var snippet = matchFunction(source, methodName),
|
||||||
|
modified = snippet;
|
||||||
|
|
||||||
|
// remove native `Function#bind` branch in `_.bind`
|
||||||
|
if (methodName == 'bind') {
|
||||||
|
modified = modified.replace(/(?:\s*\/\/.*)*\s*return isBindFast[^:]+:\s*/, 'return ');
|
||||||
|
}
|
||||||
|
// remove native `Array.isArray` branch in `_.isArray`
|
||||||
|
else {
|
||||||
|
modified = modified.replace(/nativeIsArray * \|\|/, '');
|
||||||
|
}
|
||||||
|
source = source.replace(snippet, modified);
|
||||||
|
});
|
||||||
|
|
||||||
|
// replace `_.keys` with `shimKeys`
|
||||||
|
if (!isRemoved(source, 'keys')) {
|
||||||
|
source = source.replace(
|
||||||
|
matchFunction(source, 'keys').replace(/[\s\S]+?var keys *=/, ''),
|
||||||
|
matchFunction(source, 'shimKeys').replace(/[\s\S]+?var shimKeys *=/, '')
|
||||||
|
);
|
||||||
|
|
||||||
|
source = removeFunction(source, 'shimKeys');
|
||||||
|
}
|
||||||
|
// replace `_.isArguments` with fallback
|
||||||
|
if (!isRemoved(source, 'isArguments')) {
|
||||||
|
source = source.replace(
|
||||||
|
matchFunction(source, 'isArguments').replace(/[\s\S]+?function isArguments/, ''),
|
||||||
|
getIsArgumentsFallback(source).match(/isArguments *= *function([\s\S]+?) *};/)[1] + ' }\n'
|
||||||
|
);
|
||||||
|
|
||||||
|
source = removeIsArgumentsFallback(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
source = removeVar(source, 'reNative');
|
||||||
|
source = removeFromCreateIterator(source, 'nativeKeys');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isMobile) {
|
||||||
|
// inline all functions defined with `createIterator`
|
||||||
|
_.functions(lodash).forEach(function(methodName) {
|
||||||
|
// match `methodName` with pseudo private `_` prefixes removed to allow matching `shimKeys`
|
||||||
|
var reFunc = RegExp('(\\bvar ' + methodName.replace(/^_/, '') + ' *= *)createIterator\\(((?:{|[a-zA-Z])[\\s\\S]+?)\\);\\n');
|
||||||
|
|
||||||
|
// skip if not defined with `createIterator`
|
||||||
|
if (!reFunc.test(source)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// extract, format, and inject the compiled function's source code
|
||||||
|
source = source.replace(reFunc, '$1' + getFunctionSource(lodash[methodName]) + ';\n');
|
||||||
|
});
|
||||||
|
|
||||||
|
// replace `callee` in `_.merge` with `merge`
|
||||||
|
source = source.replace(matchFunction(source, 'merge'), function(match) {
|
||||||
|
return match.replace(/\bcallee\b/g, 'merge');
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isUnderscore) {
|
||||||
|
(function() {
|
||||||
|
// replace `isArguments` and its fallback
|
||||||
|
var snippet = matchFunction(source, 'isArguments')
|
||||||
|
.replace(/function isArguments/, 'lodash.isArguments = function');
|
||||||
|
|
||||||
|
source = removeFunction(source, 'isArguments');
|
||||||
|
|
||||||
|
source = source.replace(getIsArgumentsFallback(source), function(match) {
|
||||||
|
return snippet + '\n' + match
|
||||||
|
.replace(/\bisArguments\b/g, 'lodash.$&')
|
||||||
|
.replace(/\bnoArgsClass\b/g, '!lodash.isArguments(arguments)');
|
||||||
|
});
|
||||||
|
}());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
source = removeIsArgumentsFallback(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, `noArgsEnum` assignment
|
||||||
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug\b[\s\S]+?}\(1\)\);\n/, '');
|
||||||
|
|
||||||
|
// remove `iteratesOwnLast` from `isPlainObject`
|
||||||
|
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(iteratesOwnLast[\s\S]+?\n\1}/, '');
|
||||||
|
|
||||||
|
// remove JScript [[DontEnum]] fix from `_.isEqual`
|
||||||
|
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasDontEnumBug[\s\S]+?\n\1}/, '');
|
||||||
|
|
||||||
|
// remove `hasObjectSpliceBug` fix from the mutator Array functions mixin
|
||||||
|
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasObjectSpliceBug[\s\S]+?\n\1}/, '');
|
||||||
|
|
||||||
|
// remove `noArraySliceOnStrings` from `_.toArray`
|
||||||
|
source = source.replace(/noArraySliceOnStrings *\?[^:]+: *([^)]+)/g, '$1');
|
||||||
|
|
||||||
|
// remove `noCharByIndex` from `_.reduceRight`
|
||||||
|
source = source.replace(/}\s*else if *\(noCharByIndex[^}]+/, '');
|
||||||
|
|
||||||
|
source = removeVar(source, 'extendIteratorOptions');
|
||||||
|
source = removeVar(source, 'iteratorTemplate');
|
||||||
|
source = removeVar(source, 'noArraySliceOnStrings');
|
||||||
|
source = removeVar(source, 'noCharByIndex');
|
||||||
|
source = removeNoArgsClass(source);
|
||||||
|
source = removeNoNodeClass(source);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// inline `iteratorTemplate` template
|
||||||
|
source = source.replace(/(( +)var iteratorTemplate *= *)[\s\S]+?\n\2.+?;\n/, (function() {
|
||||||
|
var snippet = getFunctionSource(lodash._iteratorTemplate);
|
||||||
|
|
||||||
|
// prepend data object references to property names to avoid having to
|
||||||
|
// use a with-statement
|
||||||
|
iteratorOptions.forEach(function(property) {
|
||||||
|
snippet = snippet.replace(RegExp('([^\\w.])\\b' + property + '\\b', 'g'), '$1obj.' + property);
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove unnecessary code
|
||||||
|
snippet = snippet
|
||||||
|
.replace(/var __t.+/, "var __p = '';")
|
||||||
|
.replace(/function print[^}]+}/, '')
|
||||||
|
.replace(/'(?:\\n|\s)+'/g, "''")
|
||||||
|
.replace(/__p *\+= *' *';/g, '')
|
||||||
|
.replace(/(__p *\+= *)' *' *\+/g, '$1')
|
||||||
|
.replace(/(\{) *;|; *(\})/g, '$1$2')
|
||||||
|
.replace(/\(\(__t *= *\( *([^)]+) *\)\) *== *null *\? *'' *: *__t\)/g, '$1');
|
||||||
|
|
||||||
|
// remove the with-statement
|
||||||
|
snippet = snippet.replace(/ *with *\(.+?\) *{/, '\n').replace(/}([^}]*}[^}]*$)/, '$1');
|
||||||
|
|
||||||
|
// minor cleanup
|
||||||
|
snippet = snippet
|
||||||
|
.replace(/obj *\|\| *\(obj *= *\{}\);/, '')
|
||||||
|
.replace(/var __p = '';\s*__p \+=/, 'var __p =');
|
||||||
|
|
||||||
|
// remove comments, including sourceURLs
|
||||||
|
snippet = snippet.replace(/\s*\/\/.*(?:\n|$)/g, '');
|
||||||
|
|
||||||
|
return '$1' + snippet + ';\n';
|
||||||
|
}()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
if (isLegacy) {
|
// customize Lo-Dash's IIFE
|
||||||
_.each(['isBindFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'], function(varName) {
|
(function() {
|
||||||
source = removeVar(source, varName);
|
if (typeof iife == 'string') {
|
||||||
});
|
var token = '%output%',
|
||||||
|
index = iife.indexOf(token);
|
||||||
|
|
||||||
_.each(['bind', 'isArray'], function(methodName) {
|
source = source.match(/\/\*![\s\S]+?\*\/\n/) +
|
||||||
var snippet = matchFunction(source, methodName),
|
iife.slice(0, index) +
|
||||||
modified = snippet;
|
source.replace(/^[^(]+?\(function[^{]+?{|}\(this\)\)[;\s]*$/g, '') +
|
||||||
|
iife.slice(index + token.length);
|
||||||
// remove native `Function#bind` branch in `_.bind`
|
|
||||||
if (methodName == 'bind') {
|
|
||||||
modified = modified.replace(/(?:\s*\/\/.*)*\s*return isBindFast[^:]+:\s*/, 'return ');
|
|
||||||
}
|
|
||||||
// remove native `Array.isArray` branch in `_.isArray`
|
|
||||||
else {
|
|
||||||
modified = modified.replace(/nativeIsArray * \|\|/, '');
|
|
||||||
}
|
|
||||||
source = source.replace(snippet, modified);
|
|
||||||
});
|
|
||||||
|
|
||||||
// replace `_.keys` with `shimKeys`
|
|
||||||
if (!isRemoved(source, 'keys')) {
|
|
||||||
source = source.replace(
|
|
||||||
matchFunction(source, 'keys').replace(/[\s\S]+?var keys *=/, ''),
|
|
||||||
matchFunction(source, 'shimKeys').replace(/[\s\S]+?var shimKeys *=/, '')
|
|
||||||
);
|
|
||||||
|
|
||||||
source = removeFunction(source, 'shimKeys');
|
|
||||||
}
|
}
|
||||||
// replace `_.isArguments` with fallback
|
}());
|
||||||
if (!isRemoved(source, 'isArguments')) {
|
|
||||||
source = source.replace(
|
|
||||||
matchFunction(source, 'isArguments').replace(/[\s\S]+?function isArguments/, ''),
|
|
||||||
getIsArgumentsFallback(source).match(/isArguments *= *function([\s\S]+?) *};/)[1] + ' }\n'
|
|
||||||
);
|
|
||||||
|
|
||||||
source = removeIsArgumentsFallback(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
source = removeVar(source, 'reNative');
|
|
||||||
source = removeFromCreateIterator(source, 'nativeKeys');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isMobile) {
|
|
||||||
// inline all functions defined with `createIterator`
|
|
||||||
_.functions(lodash).forEach(function(methodName) {
|
|
||||||
// match `methodName` with pseudo private `_` prefixes removed to allow matching `shimKeys`
|
|
||||||
var reFunc = RegExp('(\\bvar ' + methodName.replace(/^_/, '') + ' *= *)createIterator\\(((?:{|[a-zA-Z])[\\s\\S]+?)\\);\\n');
|
|
||||||
|
|
||||||
// skip if not defined with `createIterator`
|
|
||||||
if (!reFunc.test(source)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// extract, format, and inject the compiled function's source code
|
|
||||||
source = source.replace(reFunc, '$1' + getFunctionSource(lodash[methodName]) + ';\n');
|
|
||||||
});
|
|
||||||
|
|
||||||
// replace `callee` in `_.merge` with `merge`
|
|
||||||
source = source.replace(matchFunction(source, 'merge'), function(match) {
|
|
||||||
return match.replace(/\bcallee\b/g, 'merge');
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!isUnderscore) {
|
|
||||||
source = removeIsArgumentsFallback(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, `noArgsEnum` assignment
|
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug\b[\s\S]+?}\(1\)\);\n/, '');
|
|
||||||
|
|
||||||
// remove `iteratesOwnLast` from `isPlainObject`
|
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(iteratesOwnLast[\s\S]+?\n\1}/, '');
|
|
||||||
|
|
||||||
// remove JScript [[DontEnum]] fix from `_.isEqual`
|
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasDontEnumBug[\s\S]+?\n\1}/, '');
|
|
||||||
|
|
||||||
// remove `hasObjectSpliceBug` fix from the mutator Array functions mixin
|
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasObjectSpliceBug[\s\S]+?\n\1}/, '');
|
|
||||||
|
|
||||||
// remove `noArraySliceOnStrings` from `_.toArray`
|
|
||||||
source = source.replace(/noArraySliceOnStrings *\?[^:]+: *([^)]+)/g, '$1');
|
|
||||||
|
|
||||||
// remove `noCharByIndex` from `_.reduceRight`
|
|
||||||
source = source.replace(/}\s*else if *\(noCharByIndex[^}]+/, '');
|
|
||||||
|
|
||||||
source = removeVar(source, 'extendIteratorOptions');
|
|
||||||
source = removeVar(source, 'iteratorTemplate');
|
|
||||||
source = removeVar(source, 'noArraySliceOnStrings');
|
|
||||||
source = removeVar(source, 'noCharByIndex');
|
|
||||||
source = removeNoArgsClass(source);
|
|
||||||
source = removeNoNodeClass(source);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// inline `iteratorTemplate` template
|
|
||||||
source = source.replace(/(( +)var iteratorTemplate *= *)[\s\S]+?\n\2.+?;\n/, (function() {
|
|
||||||
var snippet = getFunctionSource(lodash._iteratorTemplate);
|
|
||||||
|
|
||||||
// prepend data object references to property names to avoid having to
|
|
||||||
// use a with-statement
|
|
||||||
iteratorOptions.forEach(function(property) {
|
|
||||||
snippet = snippet.replace(RegExp('([^\\w.])\\b' + property + '\\b', 'g'), '$1obj.' + property);
|
|
||||||
});
|
|
||||||
|
|
||||||
// remove unnecessary code
|
|
||||||
snippet = snippet
|
|
||||||
.replace(/var __t.+/, "var __p = '';")
|
|
||||||
.replace(/function print[^}]+}/, '')
|
|
||||||
.replace(/'(?:\\n|\s)+'/g, "''")
|
|
||||||
.replace(/__p *\+= *' *';/g, '')
|
|
||||||
.replace(/(__p *\+= *)' *' *\+/g, '$1')
|
|
||||||
.replace(/(\{) *;|; *(\})/g, '$1$2')
|
|
||||||
.replace(/\(\(__t *= *\( *([^)]+) *\)\) *== *null *\? *'' *: *__t\)/g, '$1');
|
|
||||||
|
|
||||||
// remove the with-statement
|
|
||||||
snippet = snippet.replace(/ *with *\(.+?\) *{/, '\n').replace(/}([^}]*}[^}]*$)/, '$1');
|
|
||||||
|
|
||||||
// minor cleanup
|
|
||||||
snippet = snippet
|
|
||||||
.replace(/obj *\|\| *\(obj *= *\{}\);/, '')
|
|
||||||
.replace(/var __p = '';\s*__p \+=/, 'var __p =');
|
|
||||||
|
|
||||||
// remove comments, including sourceURLs
|
|
||||||
snippet = snippet.replace(/\s*\/\/.*(?:\n|$)/g, '');
|
|
||||||
|
|
||||||
return '$1' + snippet + ';\n';
|
|
||||||
}()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -1156,106 +1267,87 @@
|
|||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// customize Lo-Dash's IIFE
|
if (isTemplate) {
|
||||||
(function() {
|
debugSource = source;
|
||||||
if (typeof iife == 'string') {
|
}
|
||||||
var token = '%output%',
|
else {
|
||||||
index = iife.indexOf(token);
|
// modify/remove references to removed methods/variables
|
||||||
|
if (isRemoved(source, 'isArguments')) {
|
||||||
source = source.match(/\/\*![\s\S]+?\*\/\n/) +
|
source = replaceVar(source, 'noArgsClass', 'false');
|
||||||
iife.slice(0, index) +
|
}
|
||||||
source.replace(/^[^(]+?\(function[^{]+?{|}\(this\)\)[;\s]*$/g, '') +
|
if (isRemoved(source, 'isFunction')) {
|
||||||
iife.slice(index + token.length);
|
source = removeIsFunctionFallback(source);
|
||||||
|
}
|
||||||
|
if (isRemoved(source, 'mixin')) {
|
||||||
|
// remove `LoDash` constructor
|
||||||
|
source = removeFunction(source, 'LoDash');
|
||||||
|
// remove `LoDash` calls
|
||||||
|
source = source.replace(/(?:new +LoDash(?!\()|(?:new +)?LoDash\([^)]*\));?/g, '');
|
||||||
|
// remove `LoDash.prototype` additions
|
||||||
|
source = source.replace(/(?:\s*\/\/.*)*\s*LoDash.prototype *=[\s\S]+?\/\*-+\*\//, '');
|
||||||
|
// remove `hasObjectSpliceBug` assignment
|
||||||
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasObjectSpliceBug;|.+?hasObjectSpliceBug *=.+/g, '');
|
||||||
}
|
}
|
||||||
}());
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
// remove pseudo private properties
|
||||||
|
source = source.replace(/(?:(?:\s*\/\/.*)*\s*lodash\._[^=]+=.+\n)+/g, '\n');
|
||||||
|
|
||||||
// modify/remove references to removed methods/variables
|
// assign debug source before further modifications that rely on the minifier
|
||||||
if (isRemoved(source, 'isArguments')) {
|
// to remove unused variables and other dead code
|
||||||
source = replaceVar(source, 'noArgsClass', 'false');
|
debugSource = source;
|
||||||
}
|
|
||||||
if (isRemoved(source, 'isFunction')) {
|
|
||||||
source = removeIsFunctionFallback(source);
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'mixin')) {
|
|
||||||
// remove `LoDash` constructor
|
|
||||||
source = removeFunction(source, 'LoDash');
|
|
||||||
// remove `LoDash` calls
|
|
||||||
source = source.replace(/(?:new +LoDash(?!\()|(?:new +)?LoDash\([^)]*\));?/g, '');
|
|
||||||
// remove `LoDash.prototype` additions
|
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\s*LoDash.prototype *=[\s\S]+?\/\*-+\*\//, '');
|
|
||||||
// remove `hasObjectSpliceBug` assignment
|
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasObjectSpliceBug;|.+?hasObjectSpliceBug *=.+/g, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove pseudo private properties
|
// remove associated functions, variables, and code snippets that the minifier may miss
|
||||||
source = source.replace(/(?:(?:\s*\/\/.*)*\s*lodash\._[^=]+=.+\n)+/g, '\n');
|
if (isRemoved(source, 'clone')) {
|
||||||
|
source = removeVar(source, 'cloneableClasses');
|
||||||
// assign debug source before further modifications that rely on the minifier
|
}
|
||||||
// to remove unused variables and other dead code
|
if (isRemoved(source, 'isArray')) {
|
||||||
debugSource = source;
|
source = removeVar(source, 'nativeIsArray');
|
||||||
|
}
|
||||||
// remove associated functions, variables, and code snippets that the minifier may miss
|
if (isRemoved(source, 'keys')) {
|
||||||
if (isRemoved(source, 'clone')) {
|
source = removeFunction(source, 'shimKeys');
|
||||||
source = removeVar(source, 'cloneableClasses');
|
}
|
||||||
|
if (isRemoved(source, 'template')) {
|
||||||
|
// remove `templateSettings` assignment
|
||||||
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *lodash\.templateSettings[\s\S]+?};\n/, '');
|
||||||
|
}
|
||||||
|
if (isRemoved(source, 'toArray')) {
|
||||||
|
source = removeVar(source, 'noArraySliceOnStrings');
|
||||||
|
}
|
||||||
|
if (isRemoved(source, 'clone', 'isArguments', 'isEmpty', 'isEqual')) {
|
||||||
|
source = removeNoArgsClass(source);
|
||||||
|
}
|
||||||
|
if (isRemoved(source, 'isEqual', 'isPlainObject')) {
|
||||||
|
source = removeNoNodeClass(source);
|
||||||
|
}
|
||||||
|
if ((source.match(/\bcreateIterator\b/g) || []).length < 2) {
|
||||||
|
source = removeFunction(source, 'createIterator');
|
||||||
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var noArgsEnum;|.+?noArgsEnum *=.+/g, '');
|
||||||
|
}
|
||||||
|
if (isRemoved(source, 'createIterator', 'bind')) {
|
||||||
|
source = removeVar(source, 'isBindFast');
|
||||||
|
source = removeVar(source, 'isStrictFast');
|
||||||
|
source = removeVar(source, 'nativeBind');
|
||||||
|
}
|
||||||
|
if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'keys')) {
|
||||||
|
source = removeVar(source, 'reNative');
|
||||||
|
}
|
||||||
|
if (isRemoved(source, 'createIterator', 'isEmpty', 'isEqual')) {
|
||||||
|
source = removeVar(source, 'arrayLikeClasses');
|
||||||
|
}
|
||||||
|
if (isRemoved(source, 'createIterator', 'isEqual')) {
|
||||||
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug;|.+?hasDontEnumBug *=.+/g, '');
|
||||||
|
}
|
||||||
|
if (isRemoved(source, 'createIterator', 'isPlainObject')) {
|
||||||
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var iteratesOwnLast;|.+?iteratesOwnLast *=.+/g, '');
|
||||||
|
}
|
||||||
|
if (isRemoved(source, 'createIterator', 'keys')) {
|
||||||
|
source = removeVar(source, 'nativeKeys');
|
||||||
|
}
|
||||||
|
if (!source.match(/var (?:hasDontEnumBug|hasObjectSpliceBug|iteratesOwnLast|noArgsEnum)\b/g)) {
|
||||||
|
// remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, and `noArgsEnum` assignment
|
||||||
|
source = source.replace(/ *\(function\(\) *{[\s\S]+?}\(1\)\);/, '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isRemoved(source, 'isArray')) {
|
|
||||||
source = removeVar(source, 'nativeIsArray');
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'keys')) {
|
|
||||||
source = removeFunction(source, 'shimKeys');
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'template')) {
|
|
||||||
// remove `templateSettings` assignment
|
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *lodash\.templateSettings[\s\S]+?};\n/, '');
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'toArray')) {
|
|
||||||
source = removeVar(source, 'noArraySliceOnStrings');
|
|
||||||
}
|
|
||||||
if (isUnderscore
|
|
||||||
? isRemoved(source, 'merge')
|
|
||||||
: isRemoved(source, 'clone', 'merge')
|
|
||||||
) {
|
|
||||||
source = removeFunction(source, 'isPlainObject');
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'clone', 'isArguments', 'isEmpty', 'isEqual')) {
|
|
||||||
source = removeNoArgsClass(source);
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'isEqual', 'isPlainObject')) {
|
|
||||||
source = removeNoNodeClass(source);
|
|
||||||
}
|
|
||||||
if ((source.match(/\bcreateIterator\b/g) || []).length < 2) {
|
|
||||||
source = removeFunction(source, 'createIterator');
|
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var noArgsEnum;|.+?noArgsEnum *=.+/g, '');
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'createIterator', 'bind')) {
|
|
||||||
source = removeVar(source, 'isBindFast');
|
|
||||||
source = removeVar(source, 'isStrictFast');
|
|
||||||
source = removeVar(source, 'nativeBind');
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'keys')) {
|
|
||||||
source = removeVar(source, 'reNative');
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'createIterator', 'isEmpty', 'isEqual')) {
|
|
||||||
source = removeVar(source, 'arrayLikeClasses');
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'createIterator', 'isEqual')) {
|
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var hasDontEnumBug;|.+?hasDontEnumBug *=.+/g, '');
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'createIterator', 'isPlainObject')) {
|
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *var iteratesOwnLast;|.+?iteratesOwnLast *=.+/g, '');
|
|
||||||
}
|
|
||||||
if (isRemoved(source, 'createIterator', 'keys')) {
|
|
||||||
source = removeVar(source, 'nativeKeys');
|
|
||||||
}
|
|
||||||
if (!source.match(/var (?:hasDontEnumBug|hasObjectSpliceBug|iteratesOwnLast|noArgsEnum)\b/g)) {
|
|
||||||
// remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, and `noArgsEnum` assignment
|
|
||||||
source = source.replace(/ *\(function\(\) *{[\s\S]+?}\(1\)\);/, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
debugSource = cleanupSource(debugSource);
|
|
||||||
source = cleanupSource(source);
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@@ -1265,35 +1357,43 @@
|
|||||||
!_.isEqual(exportsOptions, exportsAll);
|
!_.isEqual(exportsOptions, exportsAll);
|
||||||
|
|
||||||
// used to name temporary files created in `dist/`
|
// used to name temporary files created in `dist/`
|
||||||
var workingName = 'lodash' + (isCustom ? '.custom' : '') + '.min';
|
var workingName = 'lodash' + (isTemplate ? '.template' : isCustom ? '.custom' : '');
|
||||||
|
|
||||||
// restore `dependencyMap`
|
// restore `dependencyMap`
|
||||||
dependencyMap = dependencyBackup;
|
dependencyMap = dependencyBackup;
|
||||||
|
|
||||||
// output debug build
|
// output debug build
|
||||||
if (isCustom && !outputPath && !isStdOut) {
|
if (!isMinify && (isCustom || isTemplate)) {
|
||||||
callback(debugSource, path.join(cwd, 'lodash.custom.js'));
|
if (isDebug && isStdOut) {
|
||||||
|
stdout.write(debugSource);
|
||||||
|
callback(debugSource);
|
||||||
|
} else if (!isStdOut) {
|
||||||
|
callback(debugSource, (isDebug && outputPath) || path.join(cwd, workingName + '.js'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// begin the minification process
|
// begin the minification process
|
||||||
minify(source, {
|
if (!isDebug) {
|
||||||
'silent': isSilent,
|
workingName += '.min';
|
||||||
'workingName': workingName,
|
minify(source, {
|
||||||
'onComplete': function(source) {
|
'silent': isSilent,
|
||||||
// correct overly aggressive Closure Compiler minification
|
'workingName': workingName,
|
||||||
source = source.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}');
|
'onComplete': function(source) {
|
||||||
|
// correct overly aggressive Closure Compiler minification
|
||||||
|
source = source.replace(/prototype\s*=\s*{\s*valueOf\s*:\s*1\s*}/, 'prototype={valueOf:1,y:1}');
|
||||||
|
|
||||||
// inject "use strict" directive
|
// inject "use strict" directive
|
||||||
if (isStrict) {
|
if (isStrict) {
|
||||||
source = source.replace(/^(\/\*![\s\S]+?\*\/\n;\(function[^)]+\){)([^'"])/, '$1"use strict";$2');
|
source = source.replace(/^(\/\*![\s\S]+?\*\/\n;\(function[^)]+\){)([^'"])/, '$1"use strict";$2');
|
||||||
|
}
|
||||||
|
if (isStdOut) {
|
||||||
|
stdout.write(source);
|
||||||
|
callback(source);
|
||||||
|
} else {
|
||||||
|
callback(source, outputPath || path.join(cwd, workingName + '.js'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (isStdOut) {
|
});
|
||||||
stdout.write(source);
|
}
|
||||||
callback(source);
|
|
||||||
} else {
|
|
||||||
callback(source, outputPath || path.join(cwd, workingName + '.js'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -175,6 +175,7 @@
|
|||||||
'isNull',
|
'isNull',
|
||||||
'isNumber',
|
'isNumber',
|
||||||
'isObject',
|
'isObject',
|
||||||
|
'isPlainObject',
|
||||||
'isRegExp',
|
'isRegExp',
|
||||||
'isString',
|
'isString',
|
||||||
'isUndefined',
|
'isUndefined',
|
||||||
@@ -217,6 +218,7 @@
|
|||||||
'take',
|
'take',
|
||||||
'tap',
|
'tap',
|
||||||
'template',
|
'template',
|
||||||
|
'templates',
|
||||||
'templateSettings',
|
'templateSettings',
|
||||||
'throttle',
|
'throttle',
|
||||||
'times',
|
'times',
|
||||||
|
|||||||
@@ -62,7 +62,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
|
['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
|
||||||
if (lodash.noConflict) {
|
if (lodash && lodash.noConflict) {
|
||||||
lodashModule = lodash.noConflict();
|
lodashModule = lodash.noConflict();
|
||||||
lodashModule.moduleName = 'lodash';
|
lodashModule.moduleName = 'lodash';
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
shimmedModule = shimmed.noConflict();
|
shimmedModule = shimmed.noConflict();
|
||||||
shimmedModule.moduleName = 'shimmed';
|
shimmedModule.moduleName = 'shimmed';
|
||||||
}
|
}
|
||||||
if (underscore.noConflict) {
|
if (underscore && underscore.noConflict) {
|
||||||
underscoreModule = underscore.noConflict();
|
underscoreModule = underscore.noConflict();
|
||||||
underscoreModule.moduleName = 'underscore';
|
underscoreModule.moduleName = 'underscore';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -165,6 +165,7 @@
|
|||||||
'isNull',
|
'isNull',
|
||||||
'isNumber',
|
'isNumber',
|
||||||
'isObject',
|
'isObject',
|
||||||
|
'isPlainObject',
|
||||||
'isRegExp',
|
'isRegExp',
|
||||||
'isString',
|
'isString',
|
||||||
'isUndefined',
|
'isUndefined',
|
||||||
@@ -238,19 +239,12 @@
|
|||||||
|
|
||||||
/** List of methods used by Underscore */
|
/** List of methods used by Underscore */
|
||||||
var underscoreMethods = _.without.apply(_, [allMethods].concat([
|
var underscoreMethods = _.without.apply(_, [allMethods].concat([
|
||||||
'countBy',
|
|
||||||
'forIn',
|
'forIn',
|
||||||
'forOwn',
|
'forOwn',
|
||||||
'invert',
|
'isPlainObject',
|
||||||
'lateBind',
|
'lateBind',
|
||||||
'merge',
|
'merge',
|
||||||
'object',
|
'partial'
|
||||||
'omit',
|
|
||||||
'pairs',
|
|
||||||
'partial',
|
|
||||||
'random',
|
|
||||||
'unescape',
|
|
||||||
'where'
|
|
||||||
]));
|
]));
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
@@ -654,7 +648,7 @@
|
|||||||
|
|
||||||
asyncTest('`lodash ' + command +'`', function() {
|
asyncTest('`lodash ' + command +'`', function() {
|
||||||
build(['-s'].concat(command.split(' ')), function(source, filepath) {
|
build(['-s'].concat(command.split(' ')), function(source, filepath) {
|
||||||
equal(filepath, 'a.js', command);
|
equal(path.basename(filepath), 'a.js', command);
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -670,7 +664,7 @@
|
|||||||
var start = _.once(QUnit.start);
|
var start = _.once(QUnit.start);
|
||||||
|
|
||||||
asyncTest('`lodash ' + command +'`', function() {
|
asyncTest('`lodash ' + command +'`', function() {
|
||||||
build([command, 'exports=', 'include='], function(source, filepath) {
|
build([command, 'exports=', 'include='], function(source) {
|
||||||
equal(source, '');
|
equal(source, '');
|
||||||
equal(arguments.length, 1);
|
equal(arguments.length, 1);
|
||||||
start();
|
start();
|
||||||
|
|||||||
2
vendor/underscore/underscore-min.js
vendored
2
vendor/underscore/underscore-min.js
vendored
File diff suppressed because one or more lines are too long
31
vendor/underscore/underscore.js
vendored
31
vendor/underscore/underscore.js
vendored
@@ -105,23 +105,16 @@
|
|||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Internal data flag for performing `reduceRight`.
|
|
||||||
var right = null;
|
|
||||||
|
|
||||||
// **Reduce** builds up a single result from a list of values, aka `inject`,
|
// **Reduce** builds up a single result from a list of values, aka `inject`,
|
||||||
// or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
|
// or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
|
||||||
_.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
|
_.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
|
||||||
var initial = arguments.length > 2;
|
var initial = arguments.length > 2;
|
||||||
if (obj == null) obj = [];
|
if (obj == null) obj = [];
|
||||||
if (!right && nativeReduce && obj.reduce === nativeReduce) {
|
if (nativeReduce && obj.reduce === nativeReduce) {
|
||||||
if (context) iterator = _.bind(iterator, context);
|
if (context) iterator = _.bind(iterator, context);
|
||||||
return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
|
return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
|
||||||
}
|
}
|
||||||
each(obj, function(value, index, list) {
|
each(obj, function(value, index, list) {
|
||||||
if (right) {
|
|
||||||
index = right.keys[index];
|
|
||||||
list = right.list;
|
|
||||||
}
|
|
||||||
if (!initial) {
|
if (!initial) {
|
||||||
memo = value;
|
memo = value;
|
||||||
initial = true;
|
initial = true;
|
||||||
@@ -142,12 +135,22 @@
|
|||||||
if (context) iterator = _.bind(iterator, context);
|
if (context) iterator = _.bind(iterator, context);
|
||||||
return arguments.length > 2 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
|
return arguments.length > 2 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
|
||||||
}
|
}
|
||||||
var values = _.toArray(obj).reverse();
|
var length = obj.length;
|
||||||
if (context && !initial) iterator = _.bind(iterator, context);
|
if (length !== +length) {
|
||||||
right = {keys: _.keys(obj).reverse(), list: obj};
|
var keys = _.keys(obj);
|
||||||
var result = initial ? _.reduce(values, iterator, memo, context) : _.reduce(values, iterator);
|
length = keys.length;
|
||||||
right = null;
|
}
|
||||||
return result;
|
each(obj, function(value, index, list) {
|
||||||
|
index = keys ? keys[--length] : --length;
|
||||||
|
if (!initial) {
|
||||||
|
memo = obj[index];
|
||||||
|
initial = true;
|
||||||
|
} else {
|
||||||
|
memo = iterator.call(context, memo, obj[index], index, list);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!initial) throw new TypeError('Reduce of empty array with no initial value');
|
||||||
|
return memo;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return the first value which passes a truth test. Aliased as `detect`.
|
// Return the first value which passes a truth test. Aliased as `detect`.
|
||||||
|
|||||||
Reference in New Issue
Block a user