mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Move Underscore build _.template replacement within build.js.
Former-commit-id: 3c2971a67986e69a9ea0952056e2cdf95f73435f
This commit is contained in:
120
build.js
120
build.js
@@ -1261,6 +1261,59 @@
|
||||
' }'
|
||||
].join('\n'));
|
||||
|
||||
// replace `_.template`
|
||||
source = source.replace(/^( *)function template[\s\S]+?\n\1}/m, function() {
|
||||
return [
|
||||
' function template(text, data, options) {',
|
||||
" text || (text = '');",
|
||||
' options = defaults({}, options, lodash.templateSettings);',
|
||||
'',
|
||||
' var index = 0,',
|
||||
' source = "__p += \'",',
|
||||
' variable = options.variable;',
|
||||
'',
|
||||
' var reDelimiters = RegExp(',
|
||||
" (options.escape || reNoMatch).source + '|' +",
|
||||
" (options.interpolate || reNoMatch).source + '|' +",
|
||||
" (options.evaluate || reNoMatch).source + '|$'",
|
||||
" , 'g');",
|
||||
'',
|
||||
' text.replace(reDelimiters, function(match, escapeValue, interpolateValue, evaluateValue, offset) {',
|
||||
' source += text.slice(index, offset).replace(reUnescapedString, escapeStringChar);',
|
||||
' source +=',
|
||||
' escapeValue ? "\' +\\n_.escape(" + escapeValue + ") +\\n\'" :',
|
||||
' evaluateValue ? "\';\\n" + evaluateValue + ";\\n__p += \'" :',
|
||||
' interpolateValue ? "\' +\\n((__t = (" + interpolateValue + ")) == null ? \'\' : __t) +\\n\'" : \'\';',
|
||||
'',
|
||||
' index = offset + match.length;',
|
||||
' });',
|
||||
'',
|
||||
' source += "\';\\n";',
|
||||
' if (!variable) {',
|
||||
" variable = 'obj';",
|
||||
" source = 'with (' + variable + ' || {}) {\\n' + source + '\\n}\\n';",
|
||||
' }',
|
||||
" source = 'function(' + variable + ') {\\n' +",
|
||||
" 'var __t, __p = \\'\\', __j = Array.prototype.join;\\n' +",
|
||||
" 'function print() { __p += __j.call(arguments, \\'\\') }\\n' +",
|
||||
' source +',
|
||||
" 'return __p\\n}';",
|
||||
'',
|
||||
' try {',
|
||||
" var result = Function('_', 'return ' + source)(lodash);",
|
||||
' } catch(e) {',
|
||||
' e.source = source;',
|
||||
' throw e;',
|
||||
' }',
|
||||
' if (data) {',
|
||||
' return result(data);',
|
||||
' }',
|
||||
' result.source = source;',
|
||||
' return result;',
|
||||
' }'
|
||||
].join('\n');
|
||||
});
|
||||
|
||||
// replace `_.uniq`
|
||||
source = source.replace(/^( *)function uniq[\s\S]+?\n\1}/m, [
|
||||
' function uniq(array, isSorted, callback, thisArg) {',
|
||||
@@ -1308,6 +1361,13 @@
|
||||
' }'
|
||||
].join('\n'));
|
||||
|
||||
// remove unneeded template related variables
|
||||
source = removeVar(source, 'reComplexDelimiter');
|
||||
source = removeVar(source, 'reEmptyStringLeading');
|
||||
source = removeVar(source, 'reEmptyStringMiddle');
|
||||
source = removeVar(source, 'reEmptyStringTrailing');
|
||||
source = removeVar(source, 'reInsertVariable');
|
||||
|
||||
// remove `arguments` object check from `_.isEqual`
|
||||
source = source.replace(/ *\|\| *className *== *argsClass/, '');
|
||||
|
||||
@@ -1489,66 +1549,6 @@
|
||||
source = source.replace(matchFunction(source, 'some'), function(match) {
|
||||
return match.replace(/!\(result *= *(.+?)\);/, '(result = $1) && indicatorObject;');
|
||||
});
|
||||
|
||||
// replace `_.template`
|
||||
source = source.replace(/^( *)function template[\s\S]+?\n\1}/m, function() {
|
||||
return [
|
||||
' function template(text, data, options) {',
|
||||
" text || (text = '');",
|
||||
' options = defaults({}, options, lodash.templateSettings);',
|
||||
'',
|
||||
' var index = 0,',
|
||||
' source = "__p += \'",',
|
||||
' variable = options.variable;',
|
||||
'',
|
||||
' var reDelimiters = RegExp(',
|
||||
" (options.escape || reNoMatch).source + '|' +",
|
||||
" (options.interpolate || reNoMatch).source + '|' +",
|
||||
" (options.evaluate || reNoMatch).source + '|$'",
|
||||
" , 'g');",
|
||||
'',
|
||||
' text.replace(reDelimiters, function(match, escapeValue, interpolateValue, evaluateValue, offset) {',
|
||||
' source += text.slice(index, offset).replace(reUnescapedString, escapeStringChar);',
|
||||
' source +=',
|
||||
' escapeValue ? "\' +\\n_.escape(" + escapeValue + ") +\\n\'" :',
|
||||
' evaluateValue ? "\';\\n" + evaluateValue + ";\\n__p += \'" :',
|
||||
' interpolateValue ? "\' +\\n((__t = (" + interpolateValue + ")) == null ? \'\' : __t) +\\n\'" : \'\';',
|
||||
'',
|
||||
' index = offset + match.length;',
|
||||
' });',
|
||||
'',
|
||||
' source += "\';\\n";',
|
||||
' if (!variable) {',
|
||||
" variable = 'obj';",
|
||||
" source = 'with (' + variable + ' || {}) {\\n' + source + '\\n}\\n';",
|
||||
' }',
|
||||
" source = 'function(' + variable + ') {\\n' +",
|
||||
" 'var __t, __p = \\'\\', __j = Array.prototype.join;\\n' +",
|
||||
" 'function print() { __p += __j.call(arguments, \\'\\') }\\n' +",
|
||||
' source +',
|
||||
" 'return __p\\n}';",
|
||||
'',
|
||||
' try {',
|
||||
" var result = Function('_', 'return ' + source)(lodash);",
|
||||
' } catch(e) {',
|
||||
' e.source = source;',
|
||||
' throw e;',
|
||||
' }',
|
||||
' if (data) {',
|
||||
' return result(data);',
|
||||
' }',
|
||||
' result.source = source;',
|
||||
' return result;',
|
||||
' }'
|
||||
].join('\n');
|
||||
});
|
||||
|
||||
// remove unneeded template related variables
|
||||
source = removeVar(source, 'reComplexDelimiter');
|
||||
source = removeVar(source, 'reEmptyStringLeading');
|
||||
source = removeVar(source, 'reEmptyStringMiddle');
|
||||
source = removeVar(source, 'reEmptyStringTrailing');
|
||||
source = removeVar(source, 'reInsertVariable');
|
||||
}
|
||||
else {
|
||||
source = removeIsArgumentsFallback(source);
|
||||
|
||||
Reference in New Issue
Block a user