Where is the specification/standard for JavaScript source maps?
Asked Answered
I

1

8

I'm very used to cross-browser web APIs having a specification document owned by a standards body, e.g. the WebRTC spec from the W3C, or the WebGL spec from Khronos.

Another web API is "Source Maps", informally described in this article, and implemented in Chrome, Firefox, and elsewhere.

However, there appears to be no authoritative specification for this API/feature! All articles/implementations just link to this Google Docs URL which just says "We're sorry. You can't access this item because it is in violation of our Terms of Service."

Is this deleted Google Doc seriously the authoritative source for Source Maps? If so, how did this feature escape any reasonable standardization process? If not, where is the authoritative spec?

Inducement answered 28/9, 2020 at 13:17 Comment(5)
There is this proposed spec but it's last updated in 2013. I'm not sure how much of it, if any, is part of source map implementations or if it's related at all to that deleted document. EDIT: ...OK, apparently I'm blind. The very first thing in the page is "Note! This is a copy of the standard." and it links to that deleted document.Persian
Note that software is often written without "any reasonable standardization process". For instance, XMLHttpRequest followed no standardization process and the existing "standard" was written after XMLHttpRequest was already well entrenched.Talus
@HereticMonkey that's true - I'm just very surprised for a major feature developed as recently 2013 ...Inducement
Yeah, source maps were created by Google, and it was probably someone's 20% project, so it's probably still in beta :).Talus
The link "informally described in this article" is broken. Did you mean this one? developer.chrome.com/blog/sourcemapsGreco
C
0

Your document link has mysteriously started working again.

I tried reading it and I can't make heads or tails of what it's saying. It's like something that a student wrote to prove they know something to a teacher, but provides no explanatory power to someone trying to learn that thing.

The actual code that webpack indirectly depends on to generate the mysterious "mappings":";;;AAAA,6BAA+B;..." is in the mozilla/source-map github project:

  _serializeMappings() {
    let previousGeneratedColumn = 0;
    let previousGeneratedLine = 1;
    let previousOriginalColumn = 0;
    let previousOriginalLine = 0;
    let previousName = 0;
    let previousSource = 0;
    let result = "";
    let next;
    let mapping;
    let nameIdx;
    let sourceIdx;

    const mappings = this._mappings.toArray();
    for (let i = 0, len = mappings.length; i < len; i++) {
      mapping = mappings[i];
      next = "";

      if (mapping.generatedLine !== previousGeneratedLine) {
        previousGeneratedColumn = 0;
        while (mapping.generatedLine !== previousGeneratedLine) {
          next += ";";
          previousGeneratedLine++;
        }
      } else if (i > 0) {
        if (
          !util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])
        ) {
          continue;
        }
        next += ",";
      }

      next += base64VLQ.encode(
        mapping.generatedColumn - previousGeneratedColumn
      );
      previousGeneratedColumn = mapping.generatedColumn;

      if (mapping.source != null) {
        sourceIdx = this._sources.indexOf(mapping.source);
        next += base64VLQ.encode(sourceIdx - previousSource);
        previousSource = sourceIdx;

        // lines are stored 0-based in SourceMap spec version 3
        next += base64VLQ.encode(
          mapping.originalLine - 1 - previousOriginalLine
        );
        previousOriginalLine = mapping.originalLine - 1;

        next += base64VLQ.encode(
          mapping.originalColumn - previousOriginalColumn
        );
        previousOriginalColumn = mapping.originalColumn;

        if (mapping.name != null) {
          nameIdx = this._names.indexOf(mapping.name);
          next += base64VLQ.encode(nameIdx - previousName);
          previousName = nameIdx;
        }
      }

      result += next;
    }

    return result;
  }
Capriole answered 25/3 at 15:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.