Indexed source maps: lastColumn is not clamped to the next section when the section does not start on line 1

Offen Anfängerfreundlich
#542 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 5 Tagen

@sebxt arbeitet bereits daran.

Seit 18.10.2026.

  • #543 von @sebxt — offen
  • #551 von @user-Param — offen
  • #562 von @user-Param — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
javascript
Bereich
devtools

Rechercherichtung

Lies IndexedSourceMapConsumer und untersuche die Vergleiche von generatedPositionFor, allGeneratedPositionsFor und eachMapping mit der generierten Zeile des nächsten Abschnitts. Reproduziere das Problem mit der bereitgestellten Map mit drei Abschnitten und führe die relevanten Source-Map-Tests aus. Fertig ist die Arbeit, wenn alle drei APIs die letzte Spalte des Abschnitts auf die Grenze des nächsten Abschnitts begrenzen, wenn der Abschnitt nach Zeile 1 beginnt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

After computeColumnSpans(), IndexedSourceMapConsumer is supposed to clamp a mapping's lastColumn (or lastGeneratedColumn) so it ends where the next section begins on the same generated line. This only works for the first section, or more precisely for sections whose offset line is 0. For any later section the clamp is skipped, and in some layouts it is applied to the wrong line.

Repro:

const { SourceMapConsumer } = require("source-map");

const section = source => ({ version: 3, sources: [source], names: [], mappings: "AAAA" });

const map = await new SourceMapConsumer({
  version: 3,
  sections: [
    { offset: { line: 0, column: 0 }, map: section("a.js") },
    { offset: { line: 2, column: 0 }, map: section("b.js") },
    { offset: { line: 2, column: 10 }, map: section("c.js") },
  ],
});
map.computeColumnSpans();

map.generatedPositionFor({ source: "b.js", line: 1, column: 0 });
// actual:   { line: 3, column: 0, lastColumn: Infinity }
// expected: { line: 3, column: 0, lastColumn: 9 }

allGeneratedPositionsFor and eachMapping (lastGeneratedColumn) return the same wrong value.

Root cause: in generatedPositionFor, allGeneratedPositionsFor and eachMapping of IndexedSourceMapConsumer, the comparison line === nextSection.generatedOffset.generatedLine runs before lineShift is added, so a section relative line is compared with an absolute line from the next section's offset. It only lines up when lineShift is 0. Adding the shift before the comparison fixes it.

Vorherrschende Sprache
JavaScript
Sterne
3.7k
Forks
392
Ø Merge
4 T. 18 Std.
Gemergte PRs (30 T.)
1

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus mozilla/source-map

Alle Issues in mozilla/source-map

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.