mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37:49 +00:00
Ensure more private properties are minified correctly.
Former-commit-id: dbebbb088768f04a8252029ad709bad9f01c88bb
This commit is contained in:
@@ -87,6 +87,7 @@
|
|||||||
'any',
|
'any',
|
||||||
'argsClass',
|
'argsClass',
|
||||||
'argsObject',
|
'argsObject',
|
||||||
|
'array',
|
||||||
'assign',
|
'assign',
|
||||||
'at',
|
'at',
|
||||||
'attachEvent',
|
'attachEvent',
|
||||||
@@ -133,6 +134,7 @@
|
|||||||
'forEach',
|
'forEach',
|
||||||
'forIn',
|
'forIn',
|
||||||
'forOwn',
|
'forOwn',
|
||||||
|
'function',
|
||||||
'functions',
|
'functions',
|
||||||
'global',
|
'global',
|
||||||
'groupBy',
|
'groupBy',
|
||||||
@@ -183,6 +185,8 @@
|
|||||||
'nodeClass',
|
'nodeClass',
|
||||||
'nonEnumArgs',
|
'nonEnumArgs',
|
||||||
'nonEnumShadows',
|
'nonEnumShadows',
|
||||||
|
'null',
|
||||||
|
'number',
|
||||||
'object',
|
'object',
|
||||||
'omit',
|
'omit',
|
||||||
'once',
|
'once',
|
||||||
@@ -211,6 +215,7 @@
|
|||||||
'sortedIndex',
|
'sortedIndex',
|
||||||
'source',
|
'source',
|
||||||
'spliceObjects',
|
'spliceObjects',
|
||||||
|
'string',
|
||||||
'support',
|
'support',
|
||||||
'tail',
|
'tail',
|
||||||
'take',
|
'take',
|
||||||
@@ -222,6 +227,7 @@
|
|||||||
'toArray',
|
'toArray',
|
||||||
'trailing',
|
'trailing',
|
||||||
'transform',
|
'transform',
|
||||||
|
'undefined',
|
||||||
'unescape',
|
'unescape',
|
||||||
'unindexedChars',
|
'unindexedChars',
|
||||||
'union',
|
'union',
|
||||||
@@ -315,11 +321,11 @@
|
|||||||
// minify internal properties
|
// minify internal properties
|
||||||
(function() {
|
(function() {
|
||||||
var methods = [
|
var methods = [
|
||||||
|
'cacheIndexOf',
|
||||||
|
'cachePush',
|
||||||
'compareAscending',
|
'compareAscending',
|
||||||
'createCache',
|
'createCache',
|
||||||
'difference',
|
|
||||||
'getObject',
|
'getObject',
|
||||||
'intersection',
|
|
||||||
'releaseObject',
|
'releaseObject',
|
||||||
'sortBy',
|
'sortBy',
|
||||||
'uniq'
|
'uniq'
|
||||||
@@ -332,7 +338,7 @@
|
|||||||
'value'
|
'value'
|
||||||
];
|
];
|
||||||
|
|
||||||
var snippets = source.match(RegExp('^( +)(?:var|function) +(?:' + methods.join('|') + ')\\b[\\s\\S]+?\\n\\1}', 'gm'));
|
var snippets = source.match(RegExp('^( *)(?:var|function) +(?:' + methods.join('|') + ')\\b[\\s\\S]+?\\n\\1}', 'gm'));
|
||||||
if (!snippets) {
|
if (!snippets) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -364,14 +370,14 @@
|
|||||||
var snippets = source.match(
|
var snippets = source.match(
|
||||||
RegExp([
|
RegExp([
|
||||||
// match the `iteratorTemplate`
|
// match the `iteratorTemplate`
|
||||||
'( +)var iteratorTemplate\\b[\\s\\S]+?\\n\\1}',
|
'^( *)var iteratorTemplate\\b[\\s\\S]+?\\n\\1}',
|
||||||
// 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
|
// match variables storing `createIterator` options
|
||||||
'( +)var [a-zA-Z]+IteratorOptions\\b[\\s\\S]+?\\n\\2}',
|
'^( *)var [a-zA-Z]+IteratorOptions\\b[\\s\\S]+?\\n\\2}',
|
||||||
// match the `createIterator`, `getObject`, and `releaseObject` functions
|
// match `cachePush`, `createCache`, `createIterator`, `getObject`, `releaseObject`, and `uniq` functions
|
||||||
'( +)function (?:createIterator|getObject|releaseObject)\\b[\\s\\S]+?\\n\\3}'
|
'^( *)(?:var|function) +(?:cachePush|createCache|createIterator|getObject|releaseObject|uniq)\\b[\\s\\S]+?\\n\\3}'
|
||||||
].join('|'), 'g')
|
].join('|'), 'gm')
|
||||||
);
|
);
|
||||||
|
|
||||||
// exit early if no compilable snippets
|
// exit early if no compilable snippets
|
||||||
@@ -380,7 +386,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
snippets.forEach(function(snippet, index) {
|
snippets.forEach(function(snippet, index) {
|
||||||
var isFunc = /^ *function +/m.test(snippet),
|
var isFunc = /\bfunction *[ \w]*\(/.test(snippet),
|
||||||
isIteratorTemplate = /var iteratorTemplate\b/.test(snippet),
|
isIteratorTemplate = /var iteratorTemplate\b/.test(snippet),
|
||||||
modified = snippet;
|
modified = snippet;
|
||||||
|
|
||||||
@@ -409,16 +415,24 @@
|
|||||||
var minName = minNames[index];
|
var minName = minNames[index];
|
||||||
|
|
||||||
// minify variable names present in strings
|
// minify variable names present in strings
|
||||||
if (isFunc) {
|
if (isFunc && !isIteratorTemplate) {
|
||||||
modified = modified.replace(RegExp('(([\'"])[^\\n\\2]*?)\\b' + varName + '\\b(?=[^\\n\\2]*\\2[ ,+;]+$)', 'gm'), '$1' + minName);
|
modified = modified.replace(RegExp('((["\'])[^\\n\\2]*?)\\b' + varName + '\\b(?=[^\\n\\2]*\\2[ ,+;]+$)', 'gm'), function(match, prelude) {
|
||||||
|
return prelude + minName;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// ensure properties in compiled strings aren't minified
|
// ensure properties in compiled strings aren't minified
|
||||||
else {
|
else {
|
||||||
modified = modified.replace(RegExp('([^.])\\b' + varName + '\\b(?!\' *[\\]:])', 'g'), '$1' + minName);
|
modified = modified.replace(RegExp('([^.])\\b' + varName + '\\b(?!\' *[\\]:])', 'g'), function(match, prelude) {
|
||||||
|
return prelude + minName;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// correct `typeof` values
|
// correct `typeof` string values
|
||||||
if (/^(?:boolean|function|object|number|string|undefined)$/.test(varName)) {
|
if (/^(?:boolean|function|object|number|string|undefined)$/.test(varName)) {
|
||||||
modified = modified.replace(RegExp("(typeof [^']+')" + minName + "'", 'g'), '$1' + varName + "'");
|
modified = modified.replace(RegExp('(= *)(["\'])' + minName + '\\2|(["\'])' + minName + '\\3( *=)', 'g'), function(match, prelude, preQuote, postQuote, postlude) {
|
||||||
|
return prelude
|
||||||
|
? prelude + preQuote + varName + preQuote
|
||||||
|
: postQuote + varName + postQuote + postlude;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user