Simplify the lodash wrapper.

Former-commit-id: 389c9ca8aa8414b04f7f99caf955862a1925d42e
This commit is contained in:
John-David Dalton
2013-03-04 22:03:34 -08:00
parent 35bd7c55d0
commit b92105e888
9 changed files with 326 additions and 385 deletions

View File

@@ -1144,6 +1144,25 @@
return source;
}
/**
* Removes all `lodashWrapper` references from `source`.
*
* @private
* @param {String} source The source to process.
* @returns {String} Returns the modified source.
*/
function removeLodashWrapper(source) {
source = removeFunction(source, 'lodashWrapper');
// remove `lodashWrapper.prototype` assignment
source = source.replace(/(?:\s*\/\/.*)*\n *lodashWrapper\.prototype *=.+/, '');
// replace `new lodashWrapper` with `new lodash`
source = source.replace(/\bnew lodashWrapper\b/g, 'new lodash');
return source;
}
/**
* Removes all `noArgsClass` references from `source`.
*
@@ -2017,13 +2036,9 @@
// replace `lodash`
source = replaceFunction(source, 'lodash', [
'function lodash(value) {',
' if (!(this instanceof lodash)) {',
' return new lodash(value);',
' }',
' if (value instanceof lodash) {',
' return value;',
' }',
' this.__wrapped__ = value;',
' return (value instanceof lodash)',
' ? value',
' : new lodashWrapper(value)',
'}'
].join('\n'));
@@ -2286,7 +2301,7 @@
if (isLegacy) {
source = removeSetImmediate(source);
_.each(['isBindFast', 'isIeOpera', 'isV8', 'nativeBind', 'nativeIsArray', 'nativeCreate', 'nativeKeys', 'reNative'], function(varName) {
_.each(['isBindFast', 'isIeOpera', 'isV8', 'nativeBind', 'nativeIsArray', 'nativeKeys', 'reNative'], function(varName) {
source = removeVar(source, varName);
});
@@ -2295,11 +2310,6 @@
return match.replace(/(?:\s*\/\/.*)*\s*return isBindFast[^:]+:\s*/, 'return ');
});
// remove native `Object.create` branch in `createObject`
source = source.replace(matchFunction(source, 'createObject'), function(match) {
return match.replace(/nativeCreate * \|\|\s*/, '');
});
// remove native `Array.isArray` branch in `_.isArray`
source = source.replace(matchFunction(source, 'isArray'), function(match) {
return match.replace(/nativeIsArray * \|\|\s*/, '');
@@ -2534,6 +2544,7 @@
}
if (isRemoved(source, 'value')) {
source = removeHasObjectSpliceBug(source);
source = removeLodashWrapper(source);
// simplify the `lodash` function
source = replaceFunction(source, 'lodash', [