From 6c1bbd2344bdaca4bb2be8ecf392a1e75e2956fc Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 13 Sep 2012 23:51:52 -0700 Subject: [PATCH] Tweak `iteratorTemplate` formatting and remove more code from "underscore" builds. Former-commit-id: cbaa8e41a9a60b5828d2c0da7188d483702c55e1 --- build.js | 27 ++++++++++++--------------- lodash.js | 4 ++-- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/build.js b/build.js index b5750143b..d9774aeab 100755 --- a/build.js +++ b/build.js @@ -401,7 +401,7 @@ * @returns {String} Returns the `isArguments` fallback snippet. */ 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) { return removeVar(source, 'isKeysFast') // 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` .replace(/=\s*'\s*\+\s*\(isKeysFast.+/, "= []'") // remove `isKeysFast` from `inLoop.object` of `mapIteratorOptions`, `invoke`, `pairs`, `pluck`, and `sortBy` @@ -563,7 +563,7 @@ // remove `noArgsClass` from `_.clone` and `_.isEqual` .replace(/ *\|\| *\(noArgsClass *&&[^)]+?\)\)/g, '') // 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}/, [ ' function clone(value) {', ' if (value && objectTypes[typeof value]) {', - ' var className = toString.call(value);', - ' if (!cloneableClasses[className] || (noArgsClass && isArguments(value))) {', - ' return value', - ' }', - ' return className == arrayClass', + ' return toString.call(value) == arrayClass', ' ? slice.call(value)', ' : extend({}, value)', ' }', @@ -994,16 +990,12 @@ // build replacement code _.forOwn({ - 'Arguments': 'argsClass', 'Date': 'dateClass', 'Number': 'numberClass', 'RegExp': 'regexpClass', 'String': 'stringClass' }, function(value, key) { - if (!isUnderscore && key == 'Arguments') { - return; - } var funcName = 'is' + key, funcCode = matchFunction(source, funcName); @@ -1099,9 +1091,13 @@ 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 = removeNoArgsClass(source); } // remove `hasDontEnumBug`, `hasObjectSpliceBug`, `iteratesOwnLast`, `noArgsEnum` assignment @@ -1126,6 +1122,7 @@ source = removeVar(source, 'iteratorTemplate'); source = removeVar(source, 'noArraySliceOnStrings'); source = removeVar(source, 'noCharByIndex'); + source = removeNoArgsClass(source); source = removeNoNodeClass(source); } else { @@ -1184,7 +1181,7 @@ source = source.replace(/(?: *\/\/.*\n)* *(?:else )?if *\(freeExports\) *{\s*}(?:\s*else *{\n([\s\S]+?) *})?/, '$1'); if ((source.match(/\bfreeExports\b/g) || []).length < 2) { - source = removeVar(source, 'freeExports'); + source = source.replace(/var freeExports *=[\s\S]+?;\n/, ''); } /*------------------------------------------------------------------------*/ diff --git a/lodash.js b/lodash.js index 8d950fd12..e28290c27 100644 --- a/lodash.js +++ b/lodash.js @@ -455,8 +455,8 @@ ' %>) {' + ' <% } %>\n' + ' value = iteratee[index];\n' + - ' <%= objectBranch.inLoop %>;\n' + - ' <% if (!hasDontEnumBug || useHas) { %>}\n<% } %>' + + ' <%= objectBranch.inLoop %>;' + + ' <% if (!hasDontEnumBug || useHas) { %>\n }<% } %>\n' + ' }' + ' <% } %>' +