Skip to content

Commit 31052bd

Browse files
authored
Fix emitting real mapping sources when null mapping comes first (#4082)
* Fix emitting real mapping sources when null mapping comes first * Emit a null mapping even if it has no real mappings
1 parent 62ca2ee commit 31052bd

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

internal/linker/linker.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6963,13 +6963,13 @@ func (c *linkerContext) generateSourceMapForChunk(
69636963
items := make([]item, 0, len(results))
69646964
nextSourcesIndex := 0
69656965
for _, result := range results {
6966-
if _, ok := sourceIndexToSourcesIndex[result.sourceIndex]; ok {
6966+
if result.isNullEntry {
69676967
continue
69686968
}
6969-
sourceIndexToSourcesIndex[result.sourceIndex] = nextSourcesIndex
6970-
if result.isNullEntry {
6969+
if _, ok := sourceIndexToSourcesIndex[result.sourceIndex]; ok {
69716970
continue
69726971
}
6972+
sourceIndexToSourcesIndex[result.sourceIndex] = nextSourcesIndex
69736973
file := &c.graph.Files[result.sourceIndex]
69746974

69756975
// Simple case: no nested source map
@@ -7057,7 +7057,16 @@ func (c *linkerContext) generateSourceMapForChunk(
70577057
for _, result := range results {
70587058
chunk := result.sourceMapChunk
70597059
offset := result.generatedOffset
7060-
sourcesIndex := sourceIndexToSourcesIndex[result.sourceIndex]
7060+
sourcesIndex, ok := sourceIndexToSourcesIndex[result.sourceIndex]
7061+
if !ok {
7062+
// If there's no sourcesIndex, then every mapping for this result's
7063+
// sourceIndex were null mappings. We still need to emit the null
7064+
// mapping, but its source index won't matter.
7065+
sourcesIndex = 0
7066+
if !result.isNullEntry {
7067+
panic("Internal error")
7068+
}
7069+
}
70617070

70627071
// This should have already been checked earlier
70637072
if chunk.ShouldIgnore {

0 commit comments

Comments
 (0)