@@ -5849,6 +5849,16 @@ func (c *linkerContext) generateChunkJS(chunkIndex int, chunkWaitGroup *sync.Wai
58495849 // Ignore empty source map chunks
58505850 if compileResult .SourceMapChunk .ShouldIgnore {
58515851 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+ }
58525862 } else {
58535863 prevOffset = sourcemap.LineColumnOffset {}
58545864
@@ -6330,6 +6340,16 @@ func (c *linkerContext) generateChunkCSS(chunkIndex int, chunkWaitGroup *sync.Wa
63306340 // Ignore empty source map chunks
63316341 if compileResult .SourceMapChunk .ShouldIgnore {
63326342 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+ }
63336353 } else {
63346354 prevOffset = sourcemap.LineColumnOffset {}
63356355
@@ -6902,6 +6922,7 @@ type compileResultForSourceMap struct {
69026922 sourceMapChunk sourcemap.Chunk
69036923 generatedOffset sourcemap.LineColumnOffset
69046924 sourceIndex uint32
6925+ isNullEntry bool
69056926}
69066927
69076928func (c * linkerContext ) generateSourceMapForChunk (
@@ -6929,6 +6950,9 @@ func (c *linkerContext) generateSourceMapForChunk(
69296950 continue
69306951 }
69316952 sourceIndexToSourcesIndex [result .sourceIndex ] = nextSourcesIndex
6953+ if result .isNullEntry {
6954+ continue
6955+ }
69326956 file := & c .graph .Files [result .sourceIndex ]
69336957
69346958 // Simple case: no nested source map
@@ -7044,28 +7068,38 @@ func (c *linkerContext) generateSourceMapForChunk(
70447068 startState .GeneratedColumn += prevColumnOffset
70457069 }
70467070
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 )
70497075
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
70567079 } 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+ }
70697103
70707104 // If this was all one line, include the column offset from the start
70717105 if prevEndState .GeneratedLine == 0 {
0 commit comments