8000 Make compiled templates more debuggable. · lodash/lodash@2ac887f · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ac887f

Browse files
committed
Make compiled templates more debuggable.
Former-commit-id: aba1aa3efcea6695632aae0eb61148aa3174debd
1 parent cbdc9c0 commit 2ac887f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lodash.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3421,7 +3421,11 @@
34213421
text += '\n//@ sourceURL=/lodash/template/source[' + (templateCounter++) + ']';
34223422
}
34233423

3424-
result = Function('_', 'return ' + text)(lodash);
3424+
try {
3425+
result = Function('_', 'return ' + text)(lodash);
3426+
} catch(e) {
3427+
result = function() { throw e; };
3428+
}
34253429

34263430
if (data) {
34273431
return result(data);

test/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,15 @@
734734
deepEqual(options, {});
735735
});
736736

737+
test('should be debuggable if compiled with errors', function() {
738+
var source = _.template('<% if x %>').source;
739+
ok(source.indexOf('__p') > -1);
740+
});
741+
742+
test('should raise an error if a template, compiled with errors, is executed', function() {
743+
raises(_.template('<% if x %>'));
744+
});
745+
737746
test('should work with complex "interpolate" delimiters', function() {
738747
_.each({
739748
'<%= a + b %>': '3',

0 commit comments

Comments
 (0)
0