mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Add more properties to the pre-compile whitelist and cleanup regexps.
Former-commit-id: c2d557b7bfd882b3a3b1f75011c6f32de8058350
This commit is contained in:
@@ -75,21 +75,120 @@
|
|||||||
var propWhitelist = [
|
var propWhitelist = [
|
||||||
'_',
|
'_',
|
||||||
'_wrapped',
|
'_wrapped',
|
||||||
|
'after',
|
||||||
|
'all',
|
||||||
'amd',
|
'amd',
|
||||||
|
'any',
|
||||||
|
'bind',
|
||||||
|
'bindAll',
|
||||||
|
'chain',
|
||||||
'clearTimeout',
|
'clearTimeout',
|
||||||
|
'clone',
|
||||||
|
'collect',
|
||||||
|
'compact',
|
||||||
|
'compose',
|
||||||
|
'contains',
|
||||||
'criteria',
|
'criteria',
|
||||||
|
'debounce',
|
||||||
|
'defaults',
|
||||||
|
'defer',
|
||||||
|
'delay',
|
||||||
|
'detect',
|
||||||
|
'difference',
|
||||||
|
'each',
|
||||||
|
'environment',
|
||||||
|
'escape',
|
||||||
'escape',
|
'escape',
|
||||||
'evaluate',
|
'evaluate',
|
||||||
|
'every',
|
||||||
|
'extend',
|
||||||
|
'filter',
|
||||||
|
'find',
|
||||||
|
'first',
|
||||||
|
'flatten',
|
||||||
|
'foldl',
|
||||||
|
'foldr',
|
||||||
|
'forEach',
|
||||||
|
'functions',
|
||||||
|
'groupBy',
|
||||||
|
'has',
|
||||||
|
'head',
|
||||||
|
'identity',
|
||||||
|
'include',
|
||||||
|
'indexOf',
|
||||||
|
'initial',
|
||||||
|
'inject',
|
||||||
'interpolate',
|
'interpolate',
|
||||||
|
'intersect',
|
||||||
|
'intersection',
|
||||||
|
'invoke',
|
||||||
|
'isArguments',
|
||||||
|
'isArray',
|
||||||
|
'isBoolean',
|
||||||
|
'isDate',
|
||||||
|
'isElement',
|
||||||
|
'isEmpty',
|
||||||
|
'isEqual',
|
||||||
'isEqual',
|
'isEqual',
|
||||||
'isFinite',
|
'isFinite',
|
||||||
|
'isFinite',
|
||||||
|
'isFunction',
|
||||||
|
'isNaN',
|
||||||
|
'isNull',
|
||||||
|
'isNumber',
|
||||||
|
'isObject',
|
||||||
|
'isRegExp',
|
||||||
|
'isString',
|
||||||
|
'isUndefined',
|
||||||
|
'keys',
|
||||||
|
'last',
|
||||||
|
'lastIndexOf',
|
||||||
|
'map',
|
||||||
|
'max',
|
||||||
|
'memoize',
|
||||||
|
'methods',
|
||||||
|
'min',
|
||||||
|
'mixin',
|
||||||
|
'noConflict',
|
||||||
|
'once',
|
||||||
'opera',
|
'opera',
|
||||||
|
'partial',
|
||||||
|
'pick',
|
||||||
|
'pluck',
|
||||||
|
'range',
|
||||||
|
'reduce',
|
||||||
|
'reduceRight',
|
||||||
|
'reject',
|
||||||
|
'rest',
|
||||||
|
'result',
|
||||||
|
'select',
|
||||||
'setTimeout',
|
'setTimeout',
|
||||||
|
'shuffle',
|
||||||
|
'size',
|
||||||
|
'some',
|
||||||
|
'sortBy',
|
||||||
|
'sortedIndex',
|
||||||
'source',
|
'source',
|
||||||
|
'tail',
|
||||||
|
'take',
|
||||||
|
'tap',
|
||||||
|
'template',
|
||||||
'templateSettings',
|
'templateSettings',
|
||||||
|
'throttle',
|
||||||
|
'times',
|
||||||
'toArray',
|
'toArray',
|
||||||
|
'toArray',
|
||||||
|
'union',
|
||||||
|
'uniq',
|
||||||
|
'unique',
|
||||||
|
'uniqueId',
|
||||||
'value',
|
'value',
|
||||||
'variable'
|
'values',
|
||||||
|
'variable',
|
||||||
|
'VERSION',
|
||||||
|
'without',
|
||||||
|
'wrap',
|
||||||
|
'zip'
|
||||||
];
|
];
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
@@ -105,7 +204,7 @@
|
|||||||
source = source.replace(/\/\*![\s\S]+?\*\//, '');
|
source = source.replace(/\/\*![\s\S]+?\*\//, '');
|
||||||
|
|
||||||
// correct JSDoc tags for Closure Compiler
|
// correct JSDoc tags for Closure Compiler
|
||||||
source = source.replace(/@(?:alias|category)\b[^\n]*/g, '');
|
source = source.replace(/@(?:alias|category)\b.*/g, '');
|
||||||
|
|
||||||
// add brackets to whitelisted properties so Closure Compiler won't mung them
|
// add brackets to whitelisted properties so Closure Compiler won't mung them
|
||||||
// http://code.google.com/closure/compiler/docs/api-tutorial3.html#export
|
// http://code.google.com/closure/compiler/docs/api-tutorial3.html#export
|
||||||
@@ -113,6 +212,7 @@
|
|||||||
|
|
||||||
// remove whitespace from string literals
|
// remove whitespace from string literals
|
||||||
source = source.replace(/'(?:(?=(\\?))\1.)*?'/g, function(string) {
|
source = source.replace(/'(?:(?=(\\?))\1.)*?'/g, function(string) {
|
||||||
|
// avoids removing the '\n' of the `escapes` object
|
||||||
return string.replace(/\[object |else if|function | in |return\s+[\w']|throw |typeof |use strict|var |'\\n'|\\\\n|\\n|\s+/g, function(match) {
|
return string.replace(/\[object |else if|function | in |return\s+[\w']|throw |typeof |use strict|var |'\\n'|\\\\n|\\n|\s+/g, function(match) {
|
||||||
return match == false || match == '\\n' ? '' : match;
|
return match == false || match == '\\n' ? '' : match;
|
||||||
});
|
});
|
||||||
@@ -121,7 +221,7 @@
|
|||||||
// minify `_.sortBy` internal properties
|
// minify `_.sortBy` internal properties
|
||||||
(function() {
|
(function() {
|
||||||
var properties = ['criteria', 'value'],
|
var properties = ['criteria', 'value'],
|
||||||
snippet = (source.match(/( +)function sortBy\b[\s\S]+?\n\1}/) || [])[0],
|
snippet = (source.match(/( +)function sortBy\b[\s\S]+?\n\1}/) || 0)[0],
|
||||||
result = snippet;
|
result = snippet;
|
||||||
|
|
||||||
if (snippet) {
|
if (snippet) {
|
||||||
@@ -137,14 +237,14 @@
|
|||||||
// minify all compilable snippets
|
// minify all compilable snippets
|
||||||
var snippets = source.match(
|
var snippets = source.match(
|
||||||
RegExp([
|
RegExp([
|
||||||
// match the `iterationTemplate`
|
// match the `iteratorTemplate`
|
||||||
'( +)var iteratorTemplate\\b[\\s\\S]+?\\n\\1}',
|
'var iteratorTemplate\\b[\\s\\S]+?\\);\\n',
|
||||||
// match variables storing `createIterator` options
|
|
||||||
'( +)var [a-zA-Z]+IteratorOptions\\b[\\s\\S]+?\\n\\2}',
|
|
||||||
// match the the `createIterator` function
|
|
||||||
'( +)function createIterator\\b[\\s\\S]+?\\n\\3}',
|
|
||||||
// match methods created by `createIterator` calls
|
// match methods created by `createIterator` calls
|
||||||
'createIterator\\((?:{|[a-zA-Z]+)[\\s\\S]+?\\);\\n'
|
'createIterator\\((?:{|[a-zA-Z]+)[\\s\\S]+?\\);\\n',
|
||||||
|
// match variables storing `createIterator` options
|
||||||
|
'( +)var [a-zA-Z]+IteratorOptions\\b[\\s\\S]+?\\n\\1}',
|
||||||
|
// match the the `createIterator` function
|
||||||
|
'( +)function createIterator\\b[\\s\\S]+?\\n\\2}'
|
||||||
].join('|'), 'g')
|
].join('|'), 'g')
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -158,22 +258,9 @@
|
|||||||
isIteratorTemplate = /var iteratorTemplate\b/.test(snippet),
|
isIteratorTemplate = /var iteratorTemplate\b/.test(snippet),
|
||||||
result = snippet;
|
result = snippet;
|
||||||
|
|
||||||
if (isIteratorTemplate) {
|
|
||||||
// minify delimiters
|
|
||||||
result = result
|
|
||||||
.replace(/<%=/g, '#')
|
|
||||||
.replace(/<%/g, '@')
|
|
||||||
.replace(/%>/g, '%');
|
|
||||||
|
|
||||||
// minify delimiter regexps
|
// add brackets to whitelisted properties so Closure Compiler won't mung them
|
||||||
result = result
|
result = result.replace(RegExp('\\.(' + iteratorOptions.join('|') + ')\\b', 'g'), "['$1']");
|
||||||
.replace(/('evaluate':)[^,}]+/, '$1/@([^%]+)%/g')
|
|
||||||
.replace(/('interpolate':)[^,}]+/, '$1/#([^%]+)%/g');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// add brackets to whitelisted properties so Closure Compiler won't mung them
|
|
||||||
result = result.replace(RegExp('\\.(' + iteratorOptions.join('|') + ')\\b', 'g'), "['$1']");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isCreateIterator) {
|
if (isCreateIterator) {
|
||||||
// add `true` and `false` arguments to be minified
|
// add `true` and `false` arguments to be minified
|
||||||
@@ -189,15 +276,15 @@
|
|||||||
|
|
||||||
// minify snippet variables / arguments
|
// minify snippet variables / arguments
|
||||||
compiledVars.forEach(function(variable, index) {
|
compiledVars.forEach(function(variable, index) {
|
||||||
// ensure properties in compiled strings are minified
|
// ensure properties in compiled strings aren't minified
|
||||||
result = result.replace(RegExp('([^.]\\b|\\\\n)' + variable + '\\b(?!\' *[\\]:])', 'g'), '$1' + minNames[index]);
|
result = result.replace(RegExp('([^.]\\b)' + variable + '\\b(?!\' *[\\]:])', 'g'), '$1' + minNames[index]);
|
||||||
|
|
||||||
// correct `typeof x == 'object'`
|
// correct `typeof x == 'object'`
|
||||||
if (variable == 'object') {
|
if (variable == 'object') {
|
||||||
result = result.replace(RegExp("(typeof [^']+')" + minNames[index] + "'", 'g'), "$1object'");
|
result = result.replace(RegExp("(typeof [^']+')" + minNames[index] + "'", 'g'), "$1object'");
|
||||||
}
|
}
|
||||||
// correct external boolean literals
|
// correct external boolean literals
|
||||||
if (variable == 'true' || variable == 'false') {
|
else if (variable == 'true' || variable == 'false') {
|
||||||
result = result
|
result = result
|
||||||
.replace(RegExp(': *' + minNames[index] + ',', 'g'), ':' + variable + ',')
|
.replace(RegExp(': *' + minNames[index] + ',', 'g'), ':' + variable + ',')
|
||||||
.replace(RegExp('\\b' + minNames[index] + ';', 'g'), variable + ';');
|
.replace(RegExp('\\b' + minNames[index] + ';', 'g'), variable + ';');
|
||||||
@@ -207,7 +294,7 @@
|
|||||||
// minify `createIterator` option property names
|
// minify `createIterator` option property names
|
||||||
iteratorOptions.forEach(function(property, index) {
|
iteratorOptions.forEach(function(property, index) {
|
||||||
if (isIteratorTemplate) {
|
if (isIteratorTemplate) {
|
||||||
// minify property names and accessors
|
// minify property names as interpolated template variables
|
||||||
result = result.replace(RegExp('\\b' + property + '\\b', 'g'), minNames[index]);
|
result = result.replace(RegExp('\\b' + property + '\\b', 'g'), minNames[index]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user