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

26
dist/lodash.compat.js vendored
View File

@@ -6837,7 +6837,8 @@
importsKeys = keys(imports),
importsValues = values(imports);
var isEvaluating,
var isEscaping,
isEvaluating,
index = 0,
interpolate = options.interpolate || reNoMatch,
source = "__p += '";
@@ -6858,6 +6859,7 @@
// replace delimiters with snippets
if (escapeValue) {
isEscaping = true;
source += "' +\n__e(" + escapeValue + ") +\n'";
}
if (evaluateValue) {
@@ -6878,12 +6880,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)
@@ -6891,9 +6890,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"