Remove the need to call chain on _(…) wrapped values.

Former-commit-id: 21861c88e3ec9af955d844c025b50cb32c322809
This commit is contained in:
John-David Dalton
2012-11-18 21:06:24 -08:00
parent 0c0db3babb
commit 20630aeb47
6 changed files with 66 additions and 47 deletions

View File

@@ -1166,6 +1166,15 @@
' }'
].join('\n'));
// replace `_.chain`
source = source.replace(/^( *)function chain[\s\S]+?\n\1}/m, [
' function chain(value) {',
' value = new lodash(value);',
' value.__chain__ = true;',
' return value;',
' }'
].join('\n'));
// replace `_.defaults`
source = source.replace(/^( *)var defaults *= *createIterator[\s\S]+?\);/m, [
' function defaults(object) {',
@@ -1366,6 +1375,28 @@
' }'
].join('\n'));
// replace `wrapperChain`
source = source.replace(/^( *)function wrapperChain[\s\S]+?\n\1}/m, [
' function wrapperChain() {',
' this.__chain__ = true;',
' return this;',
' }'
].join('\n'));
// add `__chain__` checks to `_.mixin` and Array function wrappers
source = source.replace(/^( *)forEach\([\s\S]+?\n\1}.+/gm, function(match) {
return match.replace(/^( *)return new lodash\(([^)]+)\).+/m, function(submatch, indent, varName) {
return indent + [
'if (this.__chain__) {',
' varName = new lodash(varName);',
' varName.__chain__ = true;',
'}',
'return varName;'
].join('\n' + indent)
.replace(/varName/g, varName);
});
});
// remove unneeded template related variables
source = removeVar(source, 'reComplexDelimiter');
source = removeVar(source, 'reEmptyStringLeading');