diff --git a/lodash.js b/lodash.js index 7c179e282..e361450a2 100644 --- a/lodash.js +++ b/lodash.js @@ -3421,7 +3421,11 @@ 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) { return result(data); diff --git a/test/test.js b/test/test.js index e2f900929..e6bed5281 100644 --- a/test/test.js +++ b/test/test.js @@ -734,6 +734,15 @@ 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() { _.each({ '<%= a + b %>': '3',