Skip to content

Commit

Permalink
Fix emitting real mapping sources when null mapping comes first (#4082)
Browse files Browse the repository at this point in the history
* Fix emitting real mapping sources when null mapping comes first

* Emit a null mapping even if it has no real mappings
  • Loading branch information
jridgewell authored Mar 9, 2025
1 parent 62ca2ee commit 31052bd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions internal/linker/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6963,13 +6963,13 @@ func (c *linkerContext) generateSourceMapForChunk(
items := make([]item, 0, len(results))
nextSourcesIndex := 0
for _, result := range results {
if _, ok := sourceIndexToSourcesIndex[result.sourceIndex]; ok {
if result.isNullEntry {
continue
}
sourceIndexToSourcesIndex[result.sourceIndex] = nextSourcesIndex
if result.isNullEntry {
if _, ok := sourceIndexToSourcesIndex[result.sourceIndex]; ok {
continue
}
sourceIndexToSourcesIndex[result.sourceIndex] = nextSourcesIndex
file := &c.graph.Files[result.sourceIndex]

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

// This should have already been checked earlier
if chunk.ShouldIgnore {
Expand Down

0 comments on commit 31052bd

Please sign in to comment.