mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 09:47:48 +00:00
Tweak iteratorTemplate formatting and remove more code from "underscore" builds.
Former-commit-id: cbaa8e41a9a60b5828d2c0da7188d483702c55e1
This commit is contained in:
27
build.js
27
build.js
@@ -401,7 +401,7 @@
|
|||||||
* @returns {String} Returns the `isArguments` fallback snippet.
|
* @returns {String} Returns the `isArguments` fallback snippet.
|
||||||
*/
|
*/
|
||||||
function getIsArgumentsFallback(source) {
|
function getIsArgumentsFallback(source) {
|
||||||
return (source.match(/(?:\s*\/\/.*)*\n( +)if *\(noArgsClass[\s\S]+?};\n\1}/) || [''])[0];
|
return (source.match(/(?:\s*\/\/.*)*\n( +)if *\((?:noArgsClass|!isArguments\(arguments\))\)[\s\S]+?};\n\1}/) || [''])[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -542,7 +542,7 @@
|
|||||||
function removeKeysOptimization(source) {
|
function removeKeysOptimization(source) {
|
||||||
return removeVar(source, 'isKeysFast')
|
return removeVar(source, 'isKeysFast')
|
||||||
// remove optimized branch in `iteratorTemplate`
|
// remove optimized branch in `iteratorTemplate`
|
||||||
.replace(/(?: *\/\/.*\n)* *'( *)<% *if *\(isKeysFast[\s\S]+?'\1<% *} *else *\{ *%>.+\n([\s\S]+?) *'\1<% *} *%>.+/, '$2')
|
.replace(/(?: *\/\/.*\n)* *'( *)<% *if *\(isKeysFast[\s\S]+?'\1<% *} *else *\{ *%>.+\n([\s\S]+?) *'\1<% *} *%>.+/, "'\\n' +\n$2")
|
||||||
// remove `isKeysFast` from `beforeLoop.object` of `mapIteratorOptions`
|
// remove `isKeysFast` from `beforeLoop.object` of `mapIteratorOptions`
|
||||||
.replace(/=\s*'\s*\+\s*\(isKeysFast.+/, "= []'")
|
.replace(/=\s*'\s*\+\s*\(isKeysFast.+/, "= []'")
|
||||||
// remove `isKeysFast` from `inLoop.object` of `mapIteratorOptions`, `invoke`, `pairs`, `pluck`, and `sortBy`
|
// remove `isKeysFast` from `inLoop.object` of `mapIteratorOptions`, `invoke`, `pairs`, `pluck`, and `sortBy`
|
||||||
@@ -563,7 +563,7 @@
|
|||||||
// remove `noArgsClass` from `_.clone` and `_.isEqual`
|
// remove `noArgsClass` from `_.clone` and `_.isEqual`
|
||||||
.replace(/ *\|\| *\(noArgsClass *&&[^)]+?\)\)/g, '')
|
.replace(/ *\|\| *\(noArgsClass *&&[^)]+?\)\)/g, '')
|
||||||
// remove `noArgsClass` from `_.isEqual`
|
// remove `noArgsClass` from `_.isEqual`
|
||||||
.replace(/if *\(noArgsClass[^}]+?}\n/, '');
|
.replace(/if *\(noArgsClass[^}]+?}\n/, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -827,11 +827,7 @@
|
|||||||
source = source.replace(/( +)function clone[\s\S]+?\n\1}/, [
|
source = source.replace(/( +)function clone[\s\S]+?\n\1}/, [
|
||||||
' function clone(value) {',
|
' function clone(value) {',
|
||||||
' if (value && objectTypes[typeof value]) {',
|
' if (value && objectTypes[typeof value]) {',
|
||||||
' var className = toString.call(value);',
|
' return toString.call(value) == arrayClass',
|
||||||
' if (!cloneableClasses[className] || (noArgsClass && isArguments(value))) {',
|
|
||||||
' return value',
|
|
||||||
' }',
|
|
||||||
' return className == arrayClass',
|
|
||||||
' ? slice.call(value)',
|
' ? slice.call(value)',
|
||||||
' : extend({}, value)',
|
' : extend({}, value)',
|
||||||
' }',
|
' }',
|
||||||
@@ -994,16 +990,12 @@
|
|||||||
|
|
||||||
// build replacement code
|
// build replacement code
|
||||||
_.forOwn({
|
_.forOwn({
|
||||||
'Arguments': 'argsClass',
|
|
||||||
'Date': 'dateClass',
|
'Date': 'dateClass',
|
||||||
'Number': 'numberClass',
|
'Number': 'numberClass',
|
||||||
'RegExp': 'regexpClass',
|
'RegExp': 'regexpClass',
|
||||||
'String': 'stringClass'
|
'String': 'stringClass'
|
||||||
},
|
},
|
||||||
function(value, key) {
|
function(value, key) {
|
||||||
if (!isUnderscore && key == 'Arguments') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var funcName = 'is' + key,
|
var funcName = 'is' + key,
|
||||||
funcCode = matchFunction(source, funcName);
|
funcCode = matchFunction(source, funcName);
|
||||||
|
|
||||||
@@ -1099,9 +1091,13 @@
|
|||||||
return match.replace(/\bcallee\b/g, 'merge');
|
return match.replace(/\bcallee\b/g, 'merge');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isUnderscore) {
|
if (isUnderscore) {
|
||||||
|
// replace `noArgsClass` from `isArguments` fallback
|
||||||
|
source = source.replace(getIsArgumentsFallback(source), function(match) {
|
||||||
|
return match.replace('noArgsClass', '!isArguments(arguments)');
|
||||||
|
});
|
||||||
|
} else {
|
||||||
source = removeIsArgumentsFallback(source);
|
source = removeIsArgumentsFallback(source);
|
||||||
source = removeNoArgsClass(source);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, `noArgsEnum` assignment
|
// remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, `noArgsEnum` assignment
|
||||||
@@ -1126,6 +1122,7 @@
|
|||||||
source = removeVar(source, 'iteratorTemplate');
|
source = removeVar(source, 'iteratorTemplate');
|
||||||
source = removeVar(source, 'noArraySliceOnStrings');
|
source = removeVar(source, 'noArraySliceOnStrings');
|
||||||
source = removeVar(source, 'noCharByIndex');
|
source = removeVar(source, 'noCharByIndex');
|
||||||
|
source = removeNoArgsClass(source);
|
||||||
source = removeNoNodeClass(source);
|
source = removeNoNodeClass(source);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1184,7 +1181,7 @@
|
|||||||
source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}(?:\s*else *{\n([\s\S]+?) *})?/, '$1');
|
source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}(?:\s*else *{\n([\s\S]+?) *})?/, '$1');
|
||||||
|
|
||||||
if ((source.match(/\bfreeExports\b/g) || []).length < 2) {
|
if ((source.match(/\bfreeExports\b/g) || []).length < 2) {
|
||||||
source = removeVar(source, 'freeExports');
|
source = source.replace(/var freeExports *=[\s\S]+?;\n/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------------*/
|
/*------------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -455,8 +455,8 @@
|
|||||||
' %>) {' +
|
' %>) {' +
|
||||||
' <% } %>\n' +
|
' <% } %>\n' +
|
||||||
' value = iteratee[index];\n' +
|
' value = iteratee[index];\n' +
|
||||||
' <%= objectBranch.inLoop %>;\n' +
|
' <%= objectBranch.inLoop %>;' +
|
||||||
' <% if (!hasDontEnumBug || useHas) { %>}\n<% } %>' +
|
' <% if (!hasDontEnumBug || useHas) { %>\n }<% } %>\n' +
|
||||||
' }' +
|
' }' +
|
||||||
' <% } %>' +
|
' <% } %>' +
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user