From:  Brian Slesinsky <skybrian@google.com>
Date:  03 Jun 2014 08:57:11 Hong Kong Time
Newsgroup:  news.mozilla.org/mozilla.dev.js-sourcemap
Subject:  

Re: Adding media type for sources to source maps

NNTP-Posting-Host:  63.245.216.66

On Mon, Jun 2, 2014 at 5:22 PM, Fitzgerald, Nick 
wrote:

>
> So you're saying that the one media type would apply for all sources? That
> works well when you have only one media type, but what about when you have
> a bunch of typescript files and one js file? It seems like it would be more
> general to define that this media type is for the first n sources, this
> media type for the second m sources... etc. Something like:
>
> ```
> sources: ["a.ts", "b.ts", "c.ts", "d.js"],
> sourcesMediaType: [
>   [3, "application/x.typescript;version=1.0.3.0"],
>   [1, "application/javascript"]
> ]
>

This seems slightly less straightforward since there's more room for
calculating the index wrong while reading or writing it, compared to a
parallel array.

I'm not sure we need to worry about the size of the parallel array. Sorting
the source files by language might be a good idea if it compresses better,
but even without that, we're talking about two characters per source file
(assuming fewer than 10 languages). If you do sort it, repeating the same
number is going to compress very well. So perhaps better to stick with the
more straightforward parallel array and let gzip handle it?

Having a special case for when every source file is the same language seems
useful mostly for readability, since a list of all zeros would compress
well too. A slightly more general rule would be to extend the parallel
array with zeros if it's shorter than the list of source files. You could
put your most commonly used language at the end (with index 0) and have a
pretty short list of mappings. But perhaps that's more confusing than
readable.

- Brian