tc39 / source-map

Source map specification, RFCs and new proposals.
https://tc39.es/source-map/
Other
130 stars 17 forks source link

Define decoding algorithms for source maps #119

Closed nicolo-ribaudo closed 2 months ago

nicolo-ribaudo commented 3 months ago

Preview: https://nicolo-ribaudo.github.io/source-map/#decoded-source-map

This PR introduces "decoded source map" data structures, which are internal spec representations of the information encoded in source maps.

It also defines algorithms to decode source maps from either a JSON string or infra representation.

The goal is:

This PR also explicitly defines sources/sourceRoot resolution in terms of the WHATWG URL spec.

There are a few points where I'm not sure about what the current/expected behavior is; I marked them with HTML comments (search for <!--). @takikawa Did you happen to figure out an answer to them while writing tests? Also, I almost everywhere used "optionally report an error", but in a few cases I wrote "throw an error" because I don't think there is a way to recover from it (for example, invalid data in the mappings string). I didn't test what implementations do though.

This PR partially fixes the first and last points of https://github.com/tc39/source-map/issues/105. Closes https://github.com/tc39/source-map/issues/123.

nicolo-ribaudo commented 2 months ago

PR updated to return i32::min for B, as discussed in the meeting last week.

nicolo-ribaudo commented 2 months ago

@takikawa Given that two of the main debuggers behave one way and two another, I added a note saying that although we support source maps with multiple contents for the same URL, if a debuger does not support showing it they will probably just pick one of the contents in an implementation-defined way.

I am not sure that describing the expected behavior in this case is a problem that we necessarily have to figure out, because the same problem can happen also when not using source maps (https://issues.chromium.org/issues/361652150). At most we could say that source maps cannot have duplicate file URLs, but we cannot ban two different source maps from introducing the same original file with two different contents anyway.