Skip to content

Commit

Permalink
Ensure _.keys use in createIterator is consistent per build.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Mar 20, 2013
1 parent aa6c47c commit c456dc0
Show file tree
Hide file tree
Showing 14 changed files with 1,212 additions and 1,212 deletions.
41 changes: 24 additions & 17 deletions build.js
Expand Up @@ -98,8 +98,8 @@
'every': ['createCallback', 'isArray'],
'filter': ['createCallback', 'isArray'],
'find': ['createCallback', 'forEach', 'isArray'],
'findIndex': [],
'findKey': [],
'findIndex': ['createCallback'],
'findKey': ['createCallback'],
'first': [],
'flatten': ['createCallback', 'isArray'],
'forEach': ['createCallback', 'isArguments', 'isArray', 'isString'],
Expand Down Expand Up @@ -190,10 +190,12 @@
'arrays',
'bottom',
'firstArg',
'init',
'loop',
'shadowedProps',
'top',
'useHas'
'useHas',
'useKeys'
];

/** List of all Lo-Dash methods */
Expand Down Expand Up @@ -923,16 +925,19 @@
*
* @private
* @param {String} source The source to process.
* @param {String} varName The name of the variable to remove.
* @param {String} identifier The name of the variable or property to remove.
* @returns {String} Returns the modified source.
*/
function removeFromCreateIterator(source, varName) {
var snippet = matchFunction(source, 'createIterator');
function removeFromCreateIterator(source, identifier) {
var snippet = matchFunction(source, 'createIterator');
if (!snippet) {
return source;
}
// remove data object property assignment
var modified = snippet.replace(RegExp("^(?: *\\/\\/.*\\n)* *'" + varName + "': *" + varName + '.+\\n+', 'm'), '');
var modified = snippet
.replace(RegExp("^(?: *\\/\\/.*\\n)* *'" + identifier + "':.+\\n+", 'm'), '')
.replace(/,(?=\s*})/, '');

source = source.replace(snippet, function() {
return modified;
});
Expand All @@ -941,7 +946,7 @@
snippet = modified.match(/Function\([\s\S]+$/)[0];

modified = snippet
.replace(RegExp('\\b' + varName + '\\b,? *', 'g'), '')
.replace(RegExp('\\b' + identifier + '\\b,? *', 'g'), '')
.replace(/, *',/, "',")
.replace(/,\s*\)/, ')')

Expand Down Expand Up @@ -1019,12 +1024,11 @@
* @returns {String} Returns the modified source.
*/
function removeKeysOptimization(source) {
source = removeVar(source, 'isJSC');
source = removeSupportProp(source, 'fastKeys');
source = removeFromCreateIterator(source, 'useKeys');

// remove optimized branch in `iteratorTemplate`
source = source.replace(getIteratorTemplate(source), function(match) {
return match.replace(/^(?: *\/\/.*\n)* *["']( *)<% *if *\(support\.fastKeys[\s\S]+?["']\1<% *} *else *{ *%>.+\n([\s\S]+?) *["']\1<% *} *%>.+/m, "'\\n' +\n$2");
return match.replace(/^(?: *\/\/.*\n)* *["']( *)<% *if *\(useHas *&& *useKeys[\s\S]+?["']\1<% *} *else *{ *%>.+\n([\s\S]+?) *["']\1<% *} *%>.+/m, "'\\n' +\n$2");
});

return source;
Expand Down Expand Up @@ -1826,7 +1830,7 @@
source = replaceVar(source, varName, 'false');
});

_.each(['argsClass', 'fastBind', 'fastKeys'], function(propName) {
_.each(['argsClass', 'fastBind'], function(propName) {
source = replaceSupportProp(source, propName, 'false');
});

Expand Down Expand Up @@ -2484,17 +2488,20 @@
if (!isRemoved(source, 'keys')) {
source = source.replace(
matchFunction(source, 'keys').replace(/[\s\S]+?var keys *= */, ''),
matchFunction(source, 'shimKeys').replace(/[\s\S]+?function shimKeys/, 'function').replace(/}\n$/, '};\n')
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 = source.replace(matchFunction(source, 'isArguments').replace(/[\s\S]+?function isArguments/, ''), function() {
var fallback = getIsArgumentsFallback(source),
body = fallback.match(/isArguments *= *function([\s\S]+? *});/)[1],
indent = getIndent(fallback);

return body.replace(RegExp('^' + indent, 'gm'), indent.slice(0, -2)) + '\n';
});

source = removeIsArgumentsFallback(source);
}
Expand Down
6 changes: 4 additions & 2 deletions build/pre-compile.js
Expand Up @@ -21,8 +21,8 @@
'isString',
'iterable',
'length',
'keys',
'lodash',
'nativeKeys',
'object',
'objectTypes',
'ownIndex',
Expand All @@ -39,10 +39,12 @@
'arrays',
'bottom',
'firstArg',
'init',
'loop',
'shadowedProps',
'top',
'useHas'
'useHas',
'useKeys'
];

/** Used to minify variables and string values to a single character */
Expand Down

0 comments on commit c456dc0

Please sign in to comment.