From:  Joseph Pecoraro <pecoraro@apple.com>
Date:  19 Apr 2013 05:02:12 Hong Kong Time
Newsgroup:  news.mozilla.org/mozilla.dev.js-sourcemap
Subject:  

RE: Change sourceMappingURL comment syntax to avoid IE JS conditional compilation issues

NNTP-Posting-Host:  63.245.216.66

On Monday, April 15, 2013 8:02:19 AM UTC-7, John Lenz wrote:
> As the last line of a file it, do it really cause any problems with IE's
> conditional code?  Can you give an example where it does?

The last line condition in the spec doesn't seem to match the current usage and implementations I've seen.

The spec currently says:

[[[
    The generated code may include a line at the end of the source, with the following form: ...
]]]


Current usage and implementations:

1. User jquery.com, the case listed above, for example. Their jquery.min.js references a sourceMappingURL at the 2nd line of the script, not the last line: [1]

/*! jQuery v1.9.1 | (c) 2005, 2012 jQuery Foundation, Inc. | jquery.org/license
//@ sourceMappingURL=jquery.min.map
*/

2. Browser implementations

	- WebKit / Blink ignore the last line constraint within JavaScript and search for the first directive [2]. In CSS however, they search the last line for a "/*@ sourceMappingURL ..." comment. [3].
	- Gecko ignores the last line constraint as well within JavaScript. It has a test for if the directive appears multiple times it takes the last one. [4][5]


3. What of the future?

	If there is another "//@ property" suggested to continue this trend, would they both also compete for the last line? The "last line" declaration is brittle for future expansion.


Proposals:

- I'd like to see the "last line" condition in the spec be dropped. If anything I'd like to see a "beginning of line" condition be added for sourceMappingURL. I haven't seen sourceMappingURL comments be used or generated not at the start of a line, and that seems reasonable to me.
- I'd also like to see clarification on which sourceMappingURL directive should be used (the first or last) directive, if there are multiple. I'd expect the last. This is an edge case though.

Although this isn't what this thread started discussing, I think it was related. Sorry if this derails discussion of the original issue.


> The format was chosen to match Firebug's "SourceURL" annotation for naming
> eval'd code (which Chrome also supports).

I don't think my "beginning of line" suggestion should apply to "sourceURL". I'm guessing that would conflict with existing usage anyways.


- Joe

[1]: http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
[2]: https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/core/inspector/ContentSearchUtils.cpp&q=sourceMappingURL&sq=package:chromium&l=172
[3]: https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/devtools/front_end/SASSSourceMapping.js&q=sourceMappingURL&sq=package:chromium&dr=C&l=164
[4]: http://mxr.mozilla.org/mozilla-beta/source/js/src/frontend/TokenStream.cpp#765
[5]: http://mxr.mozilla.org/mozilla-beta/source/js/src/jit-test/tests/debug/Script-sourceMapURL.js