8000 Ensure `sourceURL` support doesn't cause errors in Adobe's JS engine. · lodash/lodash@b60d43e · GitHub
[go: up one dir, main page]

Skip to content

Commit b60d43e

Browse files
committed
Ensure sourceURL support doesn't cause errors in Adobe's JS engine.
Former-commit-id: 2ad1214e6a58832c732499b272ebfc434953213b
1 parent a5873a3 commit b60d43e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

build/pre-compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
source = source.replace('"\';\\n"', '"\';"');
218218

219219
// remove debug sourceURL in `_.template`
220-
source = source.replace(/\+(?:\s*\/\/.*)*\s*'\/\/@ sourceURL=[^;]+/, '');
220+
source = source.replace(/(?:\s*\/\/.*\n)* *if *\(useSourceURL[^}]+}/, '');
221221

222222
// minify `_.sortBy` internal properties
223223
(function() {

lodash.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
/** Used to store tokenized template text snippets */
5555
var tokenized = [];
5656

57+
/** Detect if sourceURL syntax is usable without erroring */
58+
try {
59+
// Adobe's and Narwhal's JS engines will error
60+
var useSourceURL = (Function('//@')(), true);
61+
} catch(e){ }
62+
5763
/**
5864
* Used to escape characters for inclusion in HTML.
5965
* The `>` and `/` characters don't require escaping in HTML and have no
@@ -2641,8 +2647,9 @@
26412647
// ensure both objects have the same number of properties
26422648
if (result) {
26432649
for (prop in b) {
2644-
// Adobe JS engines have an operator precedence bug that causes `!size--`
2645-
// to produce the wrong result so it must be wrapped in parentheses.
2650+
// Adobe's JS engine, embedded in applications like InDesign, has a
2651+
// bug that causes `!size--` to throw an error so it must be wrapped
2652+
// in parentheses.
26462653
// https://github.com/documentcloud/underscore/issues/355
26472654
if (hasOwnProperty.call(b, prop) && !(size--)) {
26482655
break;
@@ -3208,11 +3215,13 @@
32083215
'var __p, __t, __j = Array.prototype.join;\n' +
32093216
'function print() { __p += __j.call(arguments, \'\') }\n' +
32103217
text +
3211-
'return __p\n}\n' +
3212-
// add sourceURL for easier debugging
3213-
// (Narwhal requires a trailing newline to prevent a syntax error)
3214-
// http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
3215-
'//@ sourceURL=/lodash/template/source[' + (templateCounter++) + ']\n';
3218+
'return __p\n}';
3219+
3220+
// add a sourceURL for easier debugging
3221+
// http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl
3222+
if (useSourceURL) {
3223+
text += '\n//@ sourceURL=/lodash/template/source[' + (templateCounter++) + ']';
3224+
}
32163225

32173226
result = Function('_', 'return ' + text)(lodash);
32183227

0 commit comments

Comments
 (0)
0