From 7de06c3dcba319cace960ddd5bcaa2ebf0e95bfd Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Mon, 20 Feb 2017 15:32:11 -0800 Subject: [PATCH] =?UTF-8?q?Ensure=20unique=20source=20maps=E2=80=99=20sour?= =?UTF-8?q?ceURL;=20closes=20#4126?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/coffeescript/browser.js | 2 ++ src/browser.coffee | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/coffeescript/browser.js b/lib/coffeescript/browser.js index a2dd3de2..4afb4c81 100644 --- a/lib/coffeescript/browser.js +++ b/lib/coffeescript/browser.js @@ -92,11 +92,13 @@ }; source = script.src || script.getAttribute('data-src'); if (source) { + options.filename = source; return CoffeeScript.load(source, function(param) { coffees[i] = param; return execute(); }, options, true); } else { + options.filename = script.id && script.id !== '' ? script.id : `coffeescript${(i !== 0 ? i : '')}`; options.sourceFiles = ['embedded']; return coffees[i] = [script.innerHTML, options]; } diff --git a/src/browser.coffee b/src/browser.coffee index f1903237..8fdaab14 100644 --- a/src/browser.coffee +++ b/src/browser.coffee @@ -69,6 +69,7 @@ runScripts = -> options = literate: script.type is coffeetypes[1] source = script.src or script.getAttribute('data-src') if source + options.filename = source CoffeeScript.load source, (param) -> coffees[i] = param @@ -76,6 +77,12 @@ runScripts = -> options true else + # `options.filename` defines how the filename the source map appears as + # in Developer Tools. If a script tag has an `id`, use that as the + # filename; otherwise use `coffeescript`, or `coffeescript1` etc. + # leaving the first one unnumbered for the common case that there’s + # only one CoffeeScript script block to parse. + options.filename = if script.id and script.id isnt '' then script.id else "coffeescript#{if i isnt 0 then i else ''}" options.sourceFiles = ['embedded'] coffees[i] = [script.innerHTML, options]