Skip to content

List source map implementations #47

Open

Description

@littledan

If we're trying to harmonize source map implementations, it would be useful to list all of the implementations we can find, so that we can then compare them. This includes both generators and consumers.

Activity

  1. bomsy commented on Jun 14, 2023

    @bomsy
    Collaborator

    These would also be super helpful for understanding the systems to be tested.

    Here is an implementation from mozilla used in firefox
    https://github.com/mozilla/source-map

  2. sjrd commented on Jun 14, 2023

    @sjrd

    I'll put forward the Scala.js compiler as generator.

    Some of our interpretations are:

    • Every source tree carries its source position through transformations (counting the entire pipeline, there are dozens of transformation phases) and eventually reaches every JavaScript AST node.
    • When printing a JS AST node, we emit source map segments that point to its position for all the text it generates, unless overridden by children nodes. So for example, an expression (a + b) attaches the parens, spaces and + sign to the position of the AST node for +, while a and b are attached to the positions of the identifier AST nodes.
    • We only give original names to the definition of identifiers. In let a = 1; a only the first a receives an original name in the source map.
    • Our source files are UTF-8 encoded usually, and strings in Scala are ~UTF-16 (like JS). In terms of output, we always emit ASCII.

    In terms of implementation, perhaps one key aspect is that it is specialized for an incremental compilation pipeline. When changing part of a source program, the entire Scala compilation pipeline is incremental end-to-end, and that until re-pretting JS AST nodes and generating source maps. Source maps are actually a pain point here, since they must be regenerated from top to bottom every time. We have an intermediate data structure consisting of Fragments to make that as efficient as we could.

    You can see our implementation here:
    https://github.com/scala-js/scala-js/blob/v1.13.1/linker/shared/src/main/scala/org/scalajs/linker/backend/javascript/SourceMapWriter.scala
    If you're not familiar with Scala, it's worth noting that this file looks nothing like typical Scala code. This is almost C code written with Scala syntax, because of how performance-sensitive it is.

  3. 7rulnik commented on Jun 14, 2023

    @7rulnik
  4. mitsuhiko commented on Jun 14, 2023

    @mitsuhiko
    Contributor

    This is our Rust library: https://crates.io/crates/sourcemap

    The most notable users of this library to the best of my knowledge are Sentry, SWC and Deno.

    It's pretty low level, we have higher level wrappers on top of that (js-source-scopes, symbolic, and symbolicator) for consumption.

  5. connor4312 commented on Jun 14, 2023

    @connor4312

    There is also https://www.npmjs.com/package/@jridgewell/source-map which is namely used in Terser. It tries to be compatible with Mozilla's source map library, but I have found some variance in the past.

  6. hybrist commented on Jun 14, 2023

    @hybrist
    Contributor

    Will there be interesting differences between uses of the libraries when it comes to what we'd want to specify? E.g. will all users of mozilla/source-map generate "spec compliant source maps in all ways we care about" as soon as mozilla/source-map has been updated in accordance with a future hardened spec?

    If not, it may also be helpful to collect things like postcss which indirectly produce source maps.

  7. jridgewell commented on Jun 14, 2023

    @jridgewell
    Member

    I maintain:

  8. ochameau commented on Jul 12, 2023

    @ochameau

    While trying to revive mozilla original source-map implementation, I went throught all major source map implementations I could easily find online and come up with this summary:
    https://docs.google.com/document/d/1cRNI5s9ECI6V7argqw0g7TDp79gNrOZiVYLIRDD9FlA/edit#heading=h.3dsnp8frk1tz
    You will see links to sources of each of them and some recap about the specifics of each.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions