1- import { GenMapping , addSegment , setSourceContent } from '@jridgewell/gen-mapping' ;
1+ import { GenMapping , maybeAddSegment , setSourceContent } from '@jridgewell/gen-mapping' ;
22import { traceSegment , decodedMappings } from '@jridgewell/trace-mapping' ;
33
44import type { TraceMap } from '@jridgewell/trace-mapping' ;
@@ -79,6 +79,8 @@ export function OriginalSource(source: string, content: string | null): Original
7979 * resolving each mapping in terms of the original source files.
8080 */
8181export function traceMappings ( tree : MapSource ) : GenMapping {
82+ // TODO: Eventually support sourceRoot, which has to be removed because the sources are already
83+ // fully resolved. We'll need to make sources relative to the sourceRoot before adding them.
8284 const gen = new GenMapping ( { file : tree . map . file } ) ;
8385 const { sources : rootSources , map } = tree ;
8486 const rootNames = map . names ;
@@ -87,10 +89,6 @@ export function traceMappings(tree: MapSource): GenMapping {
8789 for ( let i = 0 ; i < rootMappings . length ; i ++ ) {
8890 const segments = rootMappings [ i ] ;
8991
90- let lastSource = null ;
91- let lastSourceLine = null ;
92- let lastSourceColumn = null ;
93-
9492 for ( let j = 0 ; j < segments . length ; j ++ ) {
9593 const segment = segments [ j ] ;
9694 const genCol = segment [ 0 ] ;
@@ -112,19 +110,11 @@ export function traceMappings(tree: MapSource): GenMapping {
112110 if ( traced == null ) continue ;
113111 }
114112
115- // So we traced a segment down into its original source file. Now push a
116- // new segment pointing to this location.
117113 const { column, line, name, content, source } = traced ;
118- if ( line === lastSourceLine && column === lastSourceColumn && source === lastSource ) {
119- continue ;
120- }
121- lastSourceLine = line ;
122- lastSourceColumn = column ;
123- lastSource = source ;
124114
125115 // Sigh, TypeScript can't figure out source/line/column are either all null, or all non-null...
126- ( addSegment as any ) ( gen , i , genCol , source , line , column , name ) ;
127- if ( content != null ) setSourceContent ( gen , source , content ) ;
116+ ( maybeAddSegment as any ) ( gen , i , genCol , source , line , column , name ) ;
117+ if ( source && content != null ) setSourceContent ( gen , source , content ) ;
128118 }
129119 }
130120
0 commit comments