@@ -5849,6 +5849,16 @@ func (c *linkerContext) generateChunkJS(chunkIndex int, chunkWaitGroup *sync.Wai
5849
5849
// Ignore empty source map chunks
5850
5850
if compileResult .SourceMapChunk .ShouldIgnore {
5851
5851
prevOffset .AdvanceBytes (compileResult .JS )
5852
+
5853
+ // Include a null entry in the source map
5854
+ if c .options .SourceMap != config .SourceMapNone {
5855
+ if n := len (compileResultsForSourceMap ); n > 0 && ! compileResultsForSourceMap [n - 1 ].isNullEntry {
5856
+ compileResultsForSourceMap = append (compileResultsForSourceMap , compileResultForSourceMap {
5857
+ sourceIndex : compileResult .sourceIndex ,
5858
+ isNullEntry : true ,
5859
+ })
5860
+ }
5861
+ }
5852
5862
} else {
5853
5863
prevOffset = sourcemap.LineColumnOffset {}
5854
5864
@@ -6330,6 +6340,16 @@ func (c *linkerContext) generateChunkCSS(chunkIndex int, chunkWaitGroup *sync.Wa
6330
6340
// Ignore empty source map chunks
6331
6341
if compileResult .SourceMapChunk .ShouldIgnore {
6332
6342
prevOffset .AdvanceBytes (compileResult .CSS )
6343
+
6344
+ // Include a null entry in the source map
6345
+ if c .options .SourceMap != config .SourceMapNone && compileResult .sourceIndex .IsValid () {
6346
+ if n := len (compileResultsForSourceMap ); n > 0 && ! compileResultsForSourceMap [n - 1 ].isNullEntry {
6347
+ compileResultsForSourceMap = append (compileResultsForSourceMap , compileResultForSourceMap {
6348
+ sourceIndex : compileResult .sourceIndex .GetIndex (),
6349
+ isNullEntry : true ,
6350
+ })
6351
+ }
6352
+ }
6333
6353
} else {
6334
6354
prevOffset = sourcemap.LineColumnOffset {}
6335
6355
@@ -6902,6 +6922,7 @@ type compileResultForSourceMap struct {
6902
6922
sourceMapChunk sourcemap.Chunk
6903
6923
generatedOffset sourcemap.LineColumnOffset
6904
6924
sourceIndex uint32
6925
+ isNullEntry bool
6905
6926
}
6906
6927
6907
6928
func (c * linkerContext ) generateSourceMapForChunk (
@@ -6929,6 +6950,9 @@ func (c *linkerContext) generateSourceMapForChunk(
6929
6950
continue
6930
6951
}
6931
6952
sourceIndexToSourcesIndex [result .sourceIndex ] = nextSourcesIndex
6953
+ if result .isNullEntry {
6954
+ continue
6955
+ }
6932
6956
file := & c .graph .Files [result .sourceIndex ]
6933
6957
6934
6958
// Simple case: no nested source map
@@ -7044,28 +7068,38 @@ func (c *linkerContext) generateSourceMapForChunk(
7044
7068
startState .GeneratedColumn += prevColumnOffset
7045
7069
}
7046
7070
7047
- // Append the precomputed source map chunk
7048
- sourcemap .AppendSourceMapChunk (& j , prevEndState , startState , chunk .Buffer )
7071
+ if result .isNullEntry {
7072
+ // Emit a "null" mapping
7073
+ chunk .Buffer .Data = []byte ("A" )
7074
+ sourcemap .AppendSourceMapChunk (& j , prevEndState , startState , chunk .Buffer )
7049
7075
7050
- // Generate the relative offset to start from next time
7051
- prevOriginalName := prevEndState .OriginalName
7052
- prevEndState = chunk .EndState
7053
- prevEndState .SourceIndex += sourcesIndex
7054
- if chunk .Buffer .FirstNameOffset .IsValid () {
7055
- prevEndState .OriginalName += totalQuotedNameLen
7076
+ // Only the generated position was advanced
7077
+ prevEndState .GeneratedLine = startState .GeneratedLine
7078
+ prevEndState .GeneratedColumn = startState .GeneratedColumn
7056
7079
} else {
7057
- // It's possible for a chunk to have mappings but for none of those
7058
- // mappings to have an associated name. The name is optional and is
7059
- // omitted when the mapping is for a non-name token or if the final
7060
- // and original names are the same. In that case we need to restore
7061
- // the previous original name end state since it wasn't modified after
7062
- // all. If we don't do this, then files after this will adjust their
7063
- // name offsets assuming that the previous generated mapping has this
7064
- // file's offset, which is wrong.
7065
- prevEndState .OriginalName = prevOriginalName
7066
- }
7067
- prevColumnOffset = chunk .FinalGeneratedColumn
7068
- totalQuotedNameLen += len (chunk .QuotedNames )
7080
+ // Append the precomputed source map chunk
7081
+ sourcemap .AppendSourceMapChunk (& j , prevEndState , startState , chunk .Buffer )
7082
+
7083
+ // Generate the relative offset to start from next time
7084
+ prevOriginalName := prevEndState .OriginalName
7085
+ prevEndState = chunk .EndState
7086
+ prevEndState .SourceIndex += sourcesIndex
7087
+ if chunk .Buffer .FirstNameOffset .IsValid () {
7088
+ prevEndState .OriginalName += totalQuotedNameLen
7089
+ } else {
7090
+ // It's possible for a chunk to have mappings but for none of those
7091
+ // mappings to have an associated name. The name is optional and is
7092
+ // omitted when the mapping is for a non-name token or if the final
7093
+ // and original names are the same. In that case we need to restore
7094
+ // the previous original name end state since it wasn't modified after
7095
+ // all. If we don't do this, then files after this will adjust their
7096
+ // name offsets assuming that the previous generated mapping has this
7097
+ // file's offset, which is wrong.
7098
+ prevEndState .OriginalName = prevOriginalName
7099
+ }
7100
+ prevColumnOffset = chunk .FinalGeneratedColumn
7101
+ totalQuotedNameLen += len (chunk .QuotedNames )
7102
+ }
7069
7103
7070
7104
// If this was all one line, include the column offset from the start
7071
7105
if prevEndState .GeneratedLine == 0 {
0 commit comments