From:  "Fitzgerald, Nick" <nfitzgerald@mozilla.com>
Date:  05 Dec 2013 05:30:47 Hong Kong Time
Newsgroup:  news.mozilla.org/mozilla.dev.js-sourcemap
Subject:  

Re: confused about index maps

NNTP-Posting-Host:  63.245.216.66

On 11/21/13 8:02 PM, Craig Silverstein wrote:
> There are a few questions about combining sourcemaps via index maps
> that I could not figure out from the standards doc.  They probably
> just reflect my limited understanding of how sourcemaps work.
>
> 1) I can create an index map by specifying the 'sections' argument in
> the sourcemap json, but this requires each of the input files to have
> a sourcemap of its own.  What do I do if one of the input files does
> not have such a map?
>
> For instance, suppose I am combining foo.less.css and bar.css into a
> single combined file, combined.css.  (foo.less.css is a .less file
> that has been compiled to .css).  I have a sourcemap file for
> foo.less.css, created by lessc.  But I don't have anything for
> bar.css, which is just a normal .css file.  Can I create an index map
> for combined.css, and if so what entries should the 'sections'
> argument contain?
>
> Or do I have to create a sourcemap for bar.css first?  If so, how do I do that?

As it is now, you would have to create a dummy source map. I'd recommend
one mapping per line, so {line n, column 0} maps to {line n, column 0,
bar.css} for each line in bar.css.

I think it makes sense that if both the "url" and the "map" properties
are missing from a section that we assume the line and column are the
same, and only the URL is source mapped. If other implementers agree, we
can define this behavior in the spec.

>
> 2) When creating combined.css, there will be a line like
>
> //# sourceMappingURL=.../foo.less.css.map
>
> in the middle of combined.css, which lessc had put at the bottom of
> foo.less.css.  I also add a line to the bottom of combined.css:
>
> //# sourceMappingURL = .../combined.css.map
>
> Do all consumers of sourcemaps know to ignore the first
> sourceMappingURL?  The standards doc implies, but does not
> specifically state, that the sourceMappingURL is only valid if it's
> the very last line of the file.  Is that the intended semantics?  Or
> is it intended that a sourceMappingURL can be anywhere, but only the
> last occurrence in a file "wins"?

Behavior is undefined when there are multiple source map comments. The
comment is supposed to be at the bottom, but in the wild it often isn't
and so various dev tools have to be fairly loose with what they accept.
I wouldn't rely on any existing behavior when there are multiple source
map comments, and instead strip the sub-source map urls from the bundled
version.

>
> 3) If I'm combining uncompressed files, foo.js + bar.js + baz.js into
> combined.js, I might still want an index map (combined.js.map) even
> though there's no minification or other obfuscation going on.  Are
> sourcemaps intended to support this use case?  In this case, we really
> only need a mapping from line/col -> source file, that the browser
> knows how to interpret, but I get the impression that sourcemaps don't
> work that way.

The possible behavior when "map" and "url" properties are missing from a
section that I mentioned above would nicely fit this use case. You can
still use the dummy source maps for now.

Nick