From 658d14f31d197996a7c9be86e36f25326af61859 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 4 Jun 2013 08:36:45 -0700 Subject: [PATCH] Cleanup var names and properties. Former-commit-id: a3455f40184b61a7abe3f5749ea1c0a141c0e574 --- build.js | 30 +++++++++++++++++++++++------- build/pre-compile.js | 2 +- lodash.js | 37 ++++++++++++++++++++----------------- 3 files changed, 44 insertions(+), 25 deletions(-) diff --git a/build.js b/build.js index 47828d6eb..74c6b5e0a 100755 --- a/build.js +++ b/build.js @@ -224,6 +224,7 @@ 'init', 'loop', 'shadowedProps', + 'support', 'top', 'useHas', 'useKeys' @@ -1044,7 +1045,7 @@ } /** - * Removes the all references to `varName` from `createIterator` in `source`. + * Removes all references to `identifier` from `createIterator` in `source`. * * @private * @param {String} source The source to process. @@ -1076,14 +1077,23 @@ .replace(/,(?=\s*\))/, ''); }); - // remove property assignment from `getObject` - source = source.replace(matchFunction(source, 'getObject'), function(match) { + return removeFromGetObject(source, identifier); + } + + /** + * Removes all references to `identifier` from `getObject` in `source`. + * + * @private + * @param {String} source The source to process. + * @param {String} identifier The name of the property to remove. + * @returns {String} Returns the modified source. + */ + function removeFromGetObject(source, identifier) { + return source.replace(matchFunction(source, 'getObject'), function(match) { return match .replace(RegExp("^(?: *\\/\\/.*\\n)* *'" + identifier + "':.+\\n+", 'm'), '') .replace(/,(?=\s*})/, ''); }); - - return source; } /** @@ -3014,6 +3024,10 @@ if (isModern || isUnderscore) { source = removeFunction(source, 'createIterator'); + iteratorOptions.forEach(function(prop) { + source = removeFromGetObject(source, prop); + }); + // inline all functions defined with `createIterator` _.functions(lodash).forEach(function(methodName) { // strip leading underscores to match pseudo private functions @@ -3120,8 +3134,10 @@ // prepend data object references to property names to avoid having to // use a with-statement - iteratorOptions.forEach(function(property) { - snippet = snippet.replace(RegExp('([^\\w.])\\b' + property + '\\b', 'g'), '$1obj.' + property); + iteratorOptions.forEach(function(prop) { + if (prop !== 'support') { + snippet = snippet.replace(RegExp('([^\\w.])\\b' + prop + '\\b', 'g'), '$1obj.' + prop); + } }); // remove unnecessary code diff --git a/build/pre-compile.js b/build/pre-compile.js index e5daf834f..e4bc7e521 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -332,7 +332,7 @@ 'criteria', 'index', 'indexOf', - 'initArray', + 'initedArray', 'release', 'value' ]; diff --git a/lodash.js b/lodash.js index 2cf26a5eb..881d33cf4 100644 --- a/lodash.js +++ b/lodash.js @@ -167,6 +167,7 @@ 'args': null, 'array': null, 'arrays': null, + 'bottom': null, 'contains': null, 'criteria': null, 'false': null, @@ -175,7 +176,8 @@ 'index': null, 'indexOf': null, 'init': null, - 'initArray': null, + 'initedArray': null, + 'loop': null, 'null': null, 'number': null, 'object': null, @@ -184,6 +186,7 @@ 'shadowedProps': null, 'string': null, 'support': null, + 'top': null, 'true': null, 'undefined': null, 'useHas': null, @@ -919,7 +922,7 @@ function release() { var cache = this.cache; - if (cache.initArray) { + if (cache.initedArray) { releaseArray(this.array); } releaseObject(cache); @@ -928,19 +931,20 @@ return function(array) { var bailout, index = -1, - initArray = !array && (array = getArray()), + indexOf = getIndexOf(), + initedArray = !array && (array = getArray()), length = array.length, - isLarge = length >= largeArraySize && lodash.indexOf != indexOf; + isLarge = length >= largeArraySize && lodash.indexOf !== indexOf; var cache = getObject(); - cache.initArray = initArray; + cache.initedArray = initedArray; cache['false'] = cache['function'] = cache['null'] = cache['true'] = cache['undefined'] = false; var result = getObject(); result.array = array; - result.indexOf = getIndexOf(); result.cache = cache; result.contains = cacheContains; + result.indexOf = indexOf; result.push = cachePush; result.release = release; @@ -1069,7 +1073,7 @@ * @returns {Function} Returns the "indexOf" function. */ function getIndexOf(array, value, fromIndex) { - var result = (result = lodash.indexOf) == indexOf ? basicIndexOf : result; + var result = (result = lodash.indexOf) === indexOf ? basicIndexOf : result; return result; } @@ -1470,7 +1474,7 @@ return ctor(result.source, reFlags.exec(result)); } // check for circular references and return corresponding clone - var initStack = !stackA; + var initedStack = !stackA; stackA || (stackA = getArray()); stackB || (stackB = getArray()); @@ -1502,7 +1506,7 @@ result[key] = clone(objValue, deep, callback, undefined, stackA, stackB); }); - if (initStack) { + if (initedStack) { releaseArray(stackA); releaseArray(stackB); } @@ -1952,7 +1956,7 @@ // assume cyclic structures are equal // the algorithm for detecting cyclic structures is adapted from ES 5.1 // section 15.12.3, abstract operation `JO` (http://es5.github.com/#x15.12.3) - var initStack = !stackA; + var initedStack = !stackA; stackA || (stackA = getArray()); stackB || (stackB = getArray()); @@ -2016,7 +2020,7 @@ } }); } - if (initStack) { + if (initedStack) { releaseArray(stackA); releaseArray(stackB); } @@ -2329,7 +2333,7 @@ stackA = args[4], stackB = args[5]; } else { - var initStack = true; + var initedStack = true; stackA = getArray(); stackB = getArray(); @@ -2398,7 +2402,7 @@ }); } - if (initStack) { + if (initedStack) { releaseArray(stackA); releaseArray(stackB); } @@ -3987,12 +3991,11 @@ function intersection(array) { var args = arguments, argsLength = args.length, - caches = getArray(), index = -1, length = array ? array.length : 0, - isLarge = length >= largeArraySize, result = []; + var caches = getArray(); caches[0] = createCache(); outer: @@ -4385,9 +4388,9 @@ */ var uniq = overloadWrapper(function(array, isSorted, callback) { var index = -1, + indexOf = getIndexOf(), length = array ? array.length : 0, - isLarge = !isSorted && length >= largeArraySize, - indexOf = isLarge || getIndexOf(), + isLarge = !isSorted && length >= largeArraySize && lodash.indexOf !== indexOf, result = [], seen = isLarge ? createCache() : (callback ? getArray() : result);