mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Cleanup var names and properties.
Former-commit-id: a3455f40184b61a7abe3f5749ea1c0a141c0e574
This commit is contained in:
30
build.js
30
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
|
||||
|
||||
@@ -332,7 +332,7 @@
|
||||
'criteria',
|
||||
'index',
|
||||
'indexOf',
|
||||
'initArray',
|
||||
'initedArray',
|
||||
'release',
|
||||
'value'
|
||||
];
|
||||
|
||||
37
lodash.js
37
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user