Templates should not reference _.escape if "escape" delimiters are not used. [closes #484]

This commit is contained in:
John-David Dalton
2014-02-20 22:31:42 -08:00
parent b79d03d9a4
commit 8a1d2b614a
8 changed files with 104 additions and 82 deletions

View File

@@ -6874,7 +6874,8 @@
importsKeys = iteratorTemplate ? keys(imports) : ['_'],
importsValues = iteratorTemplate ? values(imports) : [lodash];
var isEvaluating,
var isEscaping,
isEvaluating,
index = 0,
interpolate = options.interpolate || reNoMatch,
source = "__p += '";
@@ -6895,6 +6896,7 @@
// replace delimiters with snippets
if (escapeValue) {
isEscaping = true;
source += "' +\n__e(" + escapeValue + ") +\n'";
}
if (evaluateValue) {
@@ -6915,12 +6917,9 @@
// if `variable` is not specified, wrap a with-statement around the generated
// code to add the data object to the top of the scope chain
var variable = options.variable,
hasVariable = variable;
if (!hasVariable) {
variable = 'obj';
source = 'with (' + variable + ') {\n' + source + '\n}\n';
var variable = options.variable;
if (!variable) {
source = 'with (obj) {\n' + source + '\n}\n';
}
// cleanup code by stripping empty strings
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
@@ -6928,9 +6927,16 @@
.replace(reEmptyStringTrailing, '$1;');
// frame code as the function body
source = 'function(' + variable + ') {\n' +
(hasVariable ? '' : variable + ' || (' + variable + ' = {});\n') +
"var __t, __p = '', __e = _.escape" +
source = 'function(' + (variable || 'obj') + ') {\n' +
(variable
? ''
: 'obj || (obj = {});\n'
) +
"var __t, __p = ''" +
(isEscaping
? ', __e = _.escape'
: ''
) +
(isEvaluating
? ', __j = Array.prototype.join;\n' +
"function print() { __p += __j.call(arguments, '') }\n"