mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Adjust how _.template handles compiled syntax errors for compatibility with Underscore.
Former-commit-id: ba84c5b468938a1be1a1fd0afd31cb83f563e1ca
This commit is contained in:
@@ -4066,10 +4066,8 @@
|
|||||||
try {
|
try {
|
||||||
result = Function('_', 'return ' + text)(lodash);
|
result = Function('_', 'return ' + text)(lodash);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
// defer syntax errors until the compiled template is executed to allow
|
e.source = text;
|
||||||
// examining the `source` property beforehand and for consistency,
|
throw e;
|
||||||
// because other template related errors occur at execution
|
|
||||||
result = function() { throw e; };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|||||||
14
test/test.js
14
test/test.js
@@ -1410,13 +1410,13 @@
|
|||||||
deepEqual(options, {});
|
deepEqual(options, {});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should be debuggable if compiled with errors', function() {
|
test('should provide the template source when a SyntaxError occurs', function() {
|
||||||
var source = _.template('<% if x %>').source;
|
try {
|
||||||
ok(source.indexOf('__p') > -1);
|
_.template('<% if x %>');
|
||||||
});
|
} catch(e) {
|
||||||
|
var source = e.source;
|
||||||
test('should raise an error if a template, compiled with errors, is executed', function() {
|
}
|
||||||
raises(_.template('<% if x %>'));
|
ok((source + '').indexOf('__p') > -1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work with complex "interpolate" delimiters', function() {
|
test('should work with complex "interpolate" delimiters', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user