mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 20:07:49 +00:00
Simplify createIterator. and remove whitespace between else { in template text.
Former-commit-id: a673f0edbe9b8655cbe1e91d9063e58130172495
This commit is contained in:
17
build.js
17
build.js
@@ -169,12 +169,12 @@
|
|||||||
/** Used to inline `iteratorTemplate` */
|
/** Used to inline `iteratorTemplate` */
|
||||||
var iteratorOptions = [
|
var iteratorOptions = [
|
||||||
'args',
|
'args',
|
||||||
'arrayLoop',
|
'arrays',
|
||||||
'bottom',
|
'bottom',
|
||||||
'firstArg',
|
'firstArg',
|
||||||
'hasDontEnumBug',
|
'hasDontEnumBug',
|
||||||
'isKeysFast',
|
'isKeysFast',
|
||||||
'objectLoop',
|
'loop',
|
||||||
'nonEnumArgs',
|
'nonEnumArgs',
|
||||||
'noCharByIndex',
|
'noCharByIndex',
|
||||||
'shadowed',
|
'shadowed',
|
||||||
@@ -893,7 +893,7 @@
|
|||||||
|
|
||||||
// remove optimized branch in `iteratorTemplate`
|
// remove optimized branch in `iteratorTemplate`
|
||||||
source = source.replace(getIteratorTemplate(source), function(match) {
|
source = source.replace(getIteratorTemplate(source), function(match) {
|
||||||
return match.replace(/(?: *\/\/.*\n)* *["']( *)<% *if *\(isKeysFast[\s\S]+?["']\1<% *} *else *\{ *%>.+\n([\s\S]+?) *["']\1<% *} *%>.+/, "'\\n' +\n$2");
|
return match.replace(/(?: *\/\/.*\n)* *["']( *)<% *if *\(isKeysFast[\s\S]+?["']\1<% *} *else *{ *%>.+\n([\s\S]+?) *["']\1<% *} *%>.+/, "'\\n' +\n$2");
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove data object property assignment in `createIterator`
|
// remove data object property assignment in `createIterator`
|
||||||
@@ -980,7 +980,7 @@
|
|||||||
*/
|
*/
|
||||||
function removeNoNodeClass(source) {
|
function removeNoNodeClass(source) {
|
||||||
// remove `noNodeClass` assignment
|
// remove `noNodeClass` assignment
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *try *\{(?:\s*\/\/.*)*\n *var noNodeClass[\s\S]+?catch[^}]+}\n/, '');
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *try *{(?:\s*\/\/.*)*\n *var noNodeClass[\s\S]+?catch[^}]+}\n/, '');
|
||||||
|
|
||||||
// remove `noNodeClass` from `shimIsPlainObject`
|
// remove `noNodeClass` from `shimIsPlainObject`
|
||||||
source = source.replace(matchFunction(source, 'shimIsPlainObject'), function(match) {
|
source = source.replace(matchFunction(source, 'shimIsPlainObject'), function(match) {
|
||||||
@@ -1097,7 +1097,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hard-codes the `useStrict` template option value for `iteratorTemplate`.
|
* Hard-codes the `strict` template option value for `iteratorTemplate`.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {String} source The source to process.
|
* @param {String} source The source to process.
|
||||||
@@ -1109,9 +1109,9 @@
|
|||||||
if (value) {
|
if (value) {
|
||||||
source = source.replace(/^[\s\S]*?function[^{]+{/, "$&\n 'use strict';");
|
source = source.replace(/^[\s\S]*?function[^{]+{/, "$&\n 'use strict';");
|
||||||
}
|
}
|
||||||
// replace `useStrict` branch in `iteratorTemplate` with hard-coded option
|
// replace `strict` branch in `iteratorTemplate` with hard-coded option
|
||||||
source = source.replace(getIteratorTemplate(source), function(match) {
|
source = source.replace(getIteratorTemplate(source), function(match) {
|
||||||
return match.replace(/(?: *\/\/.*\n)*(\s*)["'] *<%.+?useStrict.+/, value ? '$1"\'use strict\';\\n" +' : '');
|
return match.replace(/(?: *\/\/.*\n)*(\s*)["'] *<%.+?strict.+/, value ? '$1"\'use strict\';\\n" +' : '');
|
||||||
});
|
});
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
@@ -1780,7 +1780,6 @@
|
|||||||
|
|
||||||
source = removeIsArgumentsFallback(source);
|
source = removeIsArgumentsFallback(source);
|
||||||
}
|
}
|
||||||
source = removeFromCreateIterator(source, 'nativeKeys');
|
|
||||||
source = removeCreateFunction(source);
|
source = removeCreateFunction(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1916,7 +1915,7 @@
|
|||||||
.replace(/'(?:\\n|\s)+'/g, "''")
|
.replace(/'(?:\\n|\s)+'/g, "''")
|
||||||
.replace(/__p *\+= *' *';/g, '')
|
.replace(/__p *\+= *' *';/g, '')
|
||||||
.replace(/(__p *\+= *)' *' *\+/g, '$1')
|
.replace(/(__p *\+= *)' *' *\+/g, '$1')
|
||||||
.replace(/(\{) *;|; *(\})/g, '$1$2')
|
.replace(/({) *;|; *(\})/g, '$1$2')
|
||||||
.replace(/\(\(__t *= *\( *([^)]+) *\)\) *== *null *\? *'' *: *__t\)/g, '($1)');
|
.replace(/\(\(__t *= *\( *([^)]+) *\)\) *== *null *\? *'' *: *__t\)/g, '($1)');
|
||||||
|
|
||||||
// remove the with-statement
|
// remove the with-statement
|
||||||
|
|||||||
@@ -35,12 +35,12 @@
|
|||||||
/** Used to minify `compileIterator` option properties */
|
/** Used to minify `compileIterator` option properties */
|
||||||
var iteratorOptions = [
|
var iteratorOptions = [
|
||||||
'args',
|
'args',
|
||||||
'arrayLoop',
|
'arrays',
|
||||||
'bottom',
|
'bottom',
|
||||||
'firstArg',
|
'firstArg',
|
||||||
'hasDontEnumBug',
|
'hasDontEnumBug',
|
||||||
'isKeysFast',
|
'isKeysFast',
|
||||||
'objectLoop',
|
'loop',
|
||||||
'nonEnumArgs',
|
'nonEnumArgs',
|
||||||
'noCharByIndex',
|
'noCharByIndex',
|
||||||
'shadowed',
|
'shadowed',
|
||||||
@@ -235,7 +235,7 @@
|
|||||||
string = string.slice(captured.length);
|
string = string.slice(captured.length);
|
||||||
}
|
}
|
||||||
// avoids removing the '\n' of the `stringEscapes` object
|
// avoids removing the '\n' of the `stringEscapes` object
|
||||||
string = string.replace(/\[object |delete |else |function | in |return\s+[\w"']|throw |typeof |use strict|var |@ |(["'])\\n\1|\\\\n|\\n|\s+/g, function(match) {
|
string = string.replace(/\[object |delete |else (?!{)|function | in |return\s+[\w"']|throw |typeof |use strict|var |@ |(["'])\\n\1|\\\\n|\\n|\s+/g, function(match) {
|
||||||
return match == false || match == '\\n' ? '' : match;
|
return match == false || match == '\\n' ? '' : match;
|
||||||
});
|
});
|
||||||
// prepend object literal property name
|
// prepend object literal property name
|
||||||
@@ -256,7 +256,7 @@
|
|||||||
.replace('"\';\n"', '"\';"')
|
.replace('"\';\n"', '"\';"')
|
||||||
|
|
||||||
// remove `useSourceURL` variable
|
// remove `useSourceURL` variable
|
||||||
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *try *\{(?:\s*\/\/.*)*\n *var useSourceURL[\s\S]+?catch[^}]+}\n/, '');
|
source = source.replace(/(?:\n +\/\*[^*]*\*+(?:[^\/][^*]*\*+)*\/)?\n *try *{(?:\s*\/\/.*)*\n *var useSourceURL[\s\S]+?catch[^}]+}\n/, '');
|
||||||
|
|
||||||
// remove debug sourceURL use in `_.template`
|
// remove debug sourceURL use in `_.template`
|
||||||
source = source.replace(/(?:\s*\/\/.*\n)* *var sourceURL[^;]+;|\+ *sourceURL/g, '');
|
source = source.replace(/(?:\s*\/\/.*\n)* *var sourceURL[^;]+;|\+ *sourceURL/g, '');
|
||||||
|
|||||||
40
lodash.js
40
lodash.js
@@ -359,7 +359,7 @@
|
|||||||
'<%= top %>;\n' +
|
'<%= top %>;\n' +
|
||||||
|
|
||||||
// array-like iteration:
|
// array-like iteration:
|
||||||
'<% if (arrayLoop) { %>' +
|
'<% if (arrays) { %>' +
|
||||||
'var length = iteratee.length; index = -1;\n' +
|
'var length = iteratee.length; index = -1;\n' +
|
||||||
"if (typeof length == 'number') {" +
|
"if (typeof length == 'number') {" +
|
||||||
|
|
||||||
@@ -372,7 +372,7 @@
|
|||||||
|
|
||||||
// iterate over the array-like value
|
// iterate over the array-like value
|
||||||
' while (++index < length) {\n' +
|
' while (++index < length) {\n' +
|
||||||
' <%= arrayLoop %>\n' +
|
' <%= loop %>\n' +
|
||||||
' }\n' +
|
' }\n' +
|
||||||
'}\n' +
|
'}\n' +
|
||||||
'else {' +
|
'else {' +
|
||||||
@@ -384,7 +384,7 @@
|
|||||||
' if (length && isArguments(iteratee)) {\n' +
|
' if (length && isArguments(iteratee)) {\n' +
|
||||||
' while (++index < length) {\n' +
|
' while (++index < length) {\n' +
|
||||||
" index += '';\n" +
|
" index += '';\n" +
|
||||||
' <%= objectLoop %>\n' +
|
' <%= loop %>\n' +
|
||||||
' }\n' +
|
' }\n' +
|
||||||
' } else {' +
|
' } else {' +
|
||||||
' <% } %>' +
|
' <% } %>' +
|
||||||
@@ -408,7 +408,7 @@
|
|||||||
' while (++ownIndex < length) {\n' +
|
' while (++ownIndex < length) {\n' +
|
||||||
' index = ownProps[ownIndex];\n' +
|
' index = ownProps[ownIndex];\n' +
|
||||||
" <% if (!hasDontEnumBug) { %>if (!(skipProto && index == 'prototype')) {\n <% } %>" +
|
" <% if (!hasDontEnumBug) { %>if (!(skipProto && index == 'prototype')) {\n <% } %>" +
|
||||||
' <%= objectLoop %>\n' +
|
' <%= loop %>\n' +
|
||||||
' <% if (!hasDontEnumBug) { %>}\n<% } %>' +
|
' <% if (!hasDontEnumBug) { %>}\n<% } %>' +
|
||||||
' }' +
|
' }' +
|
||||||
|
|
||||||
@@ -421,7 +421,7 @@
|
|||||||
' if (useHas) { %>hasOwnProperty.call(iteratee, index)<% }' +
|
' if (useHas) { %>hasOwnProperty.call(iteratee, index)<% }' +
|
||||||
' %>) {' +
|
' %>) {' +
|
||||||
' <% } %>\n' +
|
' <% } %>\n' +
|
||||||
' <%= objectLoop %>;' +
|
' <%= loop %>;' +
|
||||||
' <% if (!hasDontEnumBug || useHas) { %>\n }<% } %>\n' +
|
' <% if (!hasDontEnumBug || useHas) { %>\n }<% } %>\n' +
|
||||||
' }' +
|
' }' +
|
||||||
' <% } %>' +
|
' <% } %>' +
|
||||||
@@ -438,11 +438,11 @@
|
|||||||
" if (shadowed[k] == 'constructor') {" +
|
" if (shadowed[k] == 'constructor') {" +
|
||||||
' %>!(ctor && ctor.prototype === iteratee) && <%' +
|
' %>!(ctor && ctor.prototype === iteratee) && <%' +
|
||||||
' } %>hasOwnProperty.call(iteratee, index)) {\n' +
|
' } %>hasOwnProperty.call(iteratee, index)) {\n' +
|
||||||
' <%= objectLoop %>\n' +
|
' <%= loop %>\n' +
|
||||||
' }' +
|
' }' +
|
||||||
' <% } %>' +
|
' <% } %>' +
|
||||||
' <% } %>' +
|
' <% } %>' +
|
||||||
' <% if (arrayLoop || nonEnumArgs) { %>\n}<% } %>\n' +
|
' <% if (arrays || nonEnumArgs) { %>\n}<% } %>\n' +
|
||||||
|
|
||||||
// add code to the bottom of the iteration function
|
// add code to the bottom of the iteration function
|
||||||
'<%= bottom %>;\n' +
|
'<%= bottom %>;\n' +
|
||||||
@@ -454,9 +454,10 @@
|
|||||||
var assignIteratorOptions = {
|
var assignIteratorOptions = {
|
||||||
'args': 'object, source, guard',
|
'args': 'object, source, guard',
|
||||||
'top':
|
'top':
|
||||||
"for (var argsIndex = 1, argsLength = typeof guard == 'number' ? 2 : arguments.length; argsIndex < argsLength; argsIndex++) {\n" +
|
"var argsIndex = 0, argsLength = typeof guard == 'number' ? 2 : arguments.length;\n" +
|
||||||
|
'while (++argsIndex < argsLength) {\n' +
|
||||||
' if ((iteratee = arguments[argsIndex])) {',
|
' if ((iteratee = arguments[argsIndex])) {',
|
||||||
'objectLoop': 'result[index] = iteratee[index]',
|
'loop': 'result[index] = iteratee[index]',
|
||||||
'bottom': ' }\n}'
|
'bottom': ' }\n}'
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -464,15 +465,15 @@
|
|||||||
* Reusable iterator options shared by `each`, `forIn`, and `forOwn`.
|
* Reusable iterator options shared by `each`, `forIn`, and `forOwn`.
|
||||||
*/
|
*/
|
||||||
var eachIteratorOptions = {
|
var eachIteratorOptions = {
|
||||||
|
'arrays': true,
|
||||||
'args': 'collection, callback, thisArg',
|
'args': 'collection, callback, thisArg',
|
||||||
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg)",
|
'top': "callback = callback && typeof thisArg == 'undefined' ? callback : createCallback(callback, thisArg)",
|
||||||
'arrayLoop': 'if (callback(iteratee[index], index, collection) === false) return result',
|
'loop': 'if (callback(iteratee[index], index, collection) === false) return result'
|
||||||
'objectLoop': 'if (callback(iteratee[index], index, collection) === false) return result'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Reusable iterator options for `forIn` and `forOwn` */
|
/** Reusable iterator options for `forIn` and `forOwn` */
|
||||||
var forOwnIteratorOptions = {
|
var forOwnIteratorOptions = {
|
||||||
'arrayLoop': null
|
'arrays': false
|
||||||
};
|
};
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
@@ -648,25 +649,28 @@
|
|||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} [options1, options2, ...] The compile options object(s).
|
* @param {Object} [options1, options2, ...] The compile options object(s).
|
||||||
|
* arrays - A boolean to specify support for iterating arrays and array-like objects.
|
||||||
* useHas - A boolean to specify using `hasOwnProperty` checks in the object loop.
|
* useHas - A boolean to specify using `hasOwnProperty` checks in the object loop.
|
||||||
* args - A string of comma separated arguments the iteration function will accept.
|
* args - A string of comma separated arguments the iteration function will accept.
|
||||||
* top - A string of code to execute before the iteration branches.
|
* top - A string of code to execute before the iteration branches.
|
||||||
* arrayLoop - A string of code to execute in the array loop.
|
* loop - A string of code to execute in the object loop.
|
||||||
* objectLoop - A string of code to execute in the object loop.
|
|
||||||
* bottom - A string of code to execute after the iteration branches.
|
* bottom - A string of code to execute after the iteration branches.
|
||||||
*
|
*
|
||||||
* @returns {Function} Returns the compiled function.
|
* @returns {Function} Returns the compiled function.
|
||||||
*/
|
*/
|
||||||
function createIterator() {
|
function createIterator() {
|
||||||
var data = {
|
var data = {
|
||||||
'arrayLoop': '',
|
// support properties
|
||||||
'bottom': '',
|
|
||||||
'hasDontEnumBug': hasDontEnumBug,
|
'hasDontEnumBug': hasDontEnumBug,
|
||||||
'isKeysFast': isKeysFast,
|
'isKeysFast': isKeysFast,
|
||||||
'objectLoop': '',
|
|
||||||
'nonEnumArgs': nonEnumArgs,
|
'nonEnumArgs': nonEnumArgs,
|
||||||
'noCharByIndex': noCharByIndex,
|
'noCharByIndex': noCharByIndex,
|
||||||
'shadowed': shadowed,
|
'shadowed': shadowed,
|
||||||
|
|
||||||
|
// iterator options
|
||||||
|
'arrays': false,
|
||||||
|
'bottom': '',
|
||||||
|
'loop': '',
|
||||||
'top': '',
|
'top': '',
|
||||||
'useHas': true
|
'useHas': true
|
||||||
};
|
};
|
||||||
@@ -1139,7 +1143,7 @@
|
|||||||
* // => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' }
|
* // => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' }
|
||||||
*/
|
*/
|
||||||
var defaults = createIterator(assignIteratorOptions, {
|
var defaults = createIterator(assignIteratorOptions, {
|
||||||
'objectLoop': 'if (result[index] == null) ' + assignIteratorOptions.objectLoop
|
'loop': 'if (result[index] == null) ' + assignIteratorOptions.loop
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user