mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Remove the need to call chain on _(…) wrapped values.
Former-commit-id: 21861c88e3ec9af955d844c025b50cb32c322809
This commit is contained in:
31
build.js
31
build.js
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user