Make compiled templates more debuggable.

Former-commit-id: aba1aa3efcea6695632aae0eb61148aa3174debd
This commit is contained in:
John-David Dalton
2012-07-11 01:52:50 -04:00
parent cbdc9c0be1
commit 2ac887ff74
2 changed files with 14 additions and 1 deletions

View File

@@ -3421,7 +3421,11 @@
text += '\n//@ sourceURL=/lodash/template/source[' + (templateCounter++) + ']'; text += '\n//@ sourceURL=/lodash/template/source[' + (templateCounter++) + ']';
} }
result = Function('_', 'return ' + text)(lodash); try {
result = Function('_', 'return ' + text)(lodash);
} catch(e) {
result = function() { throw e; };
}
if (data) { if (data) {
return result(data); return result(data);

View File

@@ -734,6 +734,15 @@
deepEqual(options, {}); deepEqual(options, {});
}); });
test('should be debuggable if compiled with errors', function() {
var source = _.template('<% if x %>').source;
ok(source.indexOf('__p') > -1);
});
test('should raise an error if a template, compiled with errors, is executed', function() {
raises(_.template('<% if x %>'));
});
test('should work with complex "interpolate" delimiters', function() { test('should work with complex "interpolate" delimiters', function() {
_.each({ _.each({
'<%= a + b %>': '3', '<%= a + b %>': '3',