diff --git a/lodash.js b/lodash.js index 7916e6482..8cd33dc2d 100644 --- a/lodash.js +++ b/lodash.js @@ -9208,8 +9208,11 @@ // Use a sourceURL for easier debugging. // See http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl. - var sourceURL = 'sourceURL' in options ? options.sourceURL : ('/lodash/template/source[' + (++templateCounter) + ']'); - sourceURL = sourceURL ? ('//# sourceURL=' + sourceURL + '\n') : ''; + var sourceURL = '//# sourceURL=' + + ('sourceURL' in options + ? options.sourceURL + : ('/lodash/template/source[' + (++templateCounter) + ']') + ) + '\n'; string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) { interpolateValue || (interpolateValue = esTemplateValue); diff --git a/test/test.js b/test/test.js index 091a5b286..6f9a0cdd7 100644 --- a/test/test.js +++ b/test/test.js @@ -11498,7 +11498,7 @@ }); }); - test('should work with no delimiters', 1, function() { + test('should work with strings without delimiters', 1, function() { var expected = 'abc'; strictEqual(_.template(expected)({}), expected); }); @@ -11695,13 +11695,44 @@ ok(pass); }); - test('should provide the template source when a SyntaxError occurs', 1, function() { + test('should expose the source for compiled templates', 1, function() { + var compiled = _.template('x'), + values = [String(compiled), compiled.source], + expected = _.map(values, _.constant(true)); + + var actual = _.map(values, function(value) { + return _.includes(value, '__p'); + }); + + deepEqual(actual, expected); + }); + + test('should expose the source when a SyntaxError occurs', 1, function() { try { _.template('<% if x %>'); } catch(e) { var source = e.source; } - ok(/__p/.test(source)); + ok(_.includes(source, '__p')); + }); + + test('should not include sourceURLs in the source', 1, function() { + var options = { 'sourceURL': '/a/b/c' }, + compiled = _.template('x', options), + values = [compiled.source, undefined]; + + try { + _.template('<% if x %>', options); + } catch(e) { + values[1] = e.source; + } + var expected = _.map(values, _.constant(false)); + + var actual = _.map(values, function(value) { + return _.includes(value, 'sourceURL'); + }); + + deepEqual(actual, expected); }); test('should work as an iteratee for `_.map`', 1, function() {