Add more checks to the reComplexDelimiter regexp.

Former-commit-id: 87fba2813619882d388261a1226e75503ec9b8d0
This commit is contained in:
John-David Dalton
2012-07-05 14:56:27 -04:00
parent 51a679d60a
commit 9d7136c63c
2 changed files with 29 additions and 4 deletions

View File

@@ -55,7 +55,7 @@
var oldDash = window._;
/** Used to detect delimiter values that should be processed by `tokenizeEvaluate` */
var reComplexDelimiter = /[-)}={(+]|\[\D/;
var reComplexDelimiter = /[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/;
/** Used to match code generated in place of template delimiters */
var reDelimiterCodeLeading = /^';\n/,

View File

@@ -671,10 +671,35 @@
});
test('should work with complex "interpolate" delimiters', function() {
var compiled = _.template('<%= a + b %>'),
data = { 'a': 1, 'b': 2 };
_.each({
'<%= a + b %>': '3',
'<%= b - a %>': '1',
'<%= a = b %>': '2',
'<%= !a %>': 'false',
'<%= ~a %>': '-2',
'<%= a * b %>': '2',
'<%= a / b %>': '0.5',
'<%= a % b %>': '1',
'<%= a >> b %>': '0',
'<%= a << b %>': '4',
'<%= a & b %>': '0',
'<%= a ^ b %>': '3',
'<%= a | b %>': '3',
'<%= {}.toString.call(0) %>': '[object Number]',
'<%= a.toFixed(2) %>': '1.00',
'<%= obj["a"] %>': '1',
'<%= delete a %>': 'true',
'<%= "a" in obj %>': 'true',
'<%= obj instanceof Object %>': 'true',
'<%= new Boolean %>': 'false',
'<%= typeof a %>': 'number',
'<%= void a %>': ''
}, function(value, key) {
var compiled = _.template(key),
data = { 'a': 1, 'b': 2 };
equal(compiled(data), 3);
equal(compiled(data), value);
});
});
}());