From d3e55931e41106378457fee1589e38dc1e27f6a9 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sun, 16 Feb 2025 01:54:24 -0500 Subject: [PATCH 1/2] Fix emitting real mapping sources when null mapping comes first --- internal/linker/linker.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/linker/linker.go b/internal/linker/linker.go index e37ed9a784d..837d1e279c1 100644 --- a/internal/linker/linker.go +++ b/internal/linker/linker.go @@ -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 @@ -7057,7 +7057,10 @@ 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 { + continue + } // This should have already been checked earlier if chunk.ShouldIgnore { From 7280b27c64b8e80f5abc96ed060a0ad5892c5631 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sun, 16 Feb 2025 02:38:52 -0500 Subject: [PATCH 2/2] Emit a null mapping even if it has no real mappings --- internal/linker/linker.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/linker/linker.go b/internal/linker/linker.go index 837d1e279c1..702399ea0d5 100644 --- a/internal/linker/linker.go +++ b/internal/linker/linker.go @@ -7059,7 +7059,13 @@ func (c *linkerContext) generateSourceMapForChunk( offset := result.generatedOffset sourcesIndex, ok := sourceIndexToSourcesIndex[result.sourceIndex] if !ok { - continue + // 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