1
- import { GenMapping , addSegment , setSourceContent } from '@jridgewell/gen-mapping' ;
1
+ import { GenMapping , maybeAddSegment , setSourceContent } from '@jridgewell/gen-mapping' ;
2
2
import { traceSegment , decodedMappings } from '@jridgewell/trace-mapping' ;
3
3
4
4
import type { TraceMap } from '@jridgewell/trace-mapping' ;
@@ -79,6 +79,8 @@ export function OriginalSource(source: string, content: string | null): Original
79
79
* resolving each mapping in terms of the original source files.
80
80
*/
81
81
export 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.
82
84
const gen = new GenMapping ( { file : tree . map . file } ) ;
83
85
const { sources : rootSources , map } = tree ;
84
86
const rootNames = map . names ;
@@ -87,10 +89,6 @@ export function traceMappings(tree: MapSource): GenMapping {
87
89
for ( let i = 0 ; i < rootMappings . length ; i ++ ) {
88
90
const segments = rootMappings [ i ] ;
89
91
90
- let lastSource = null ;
91
- let lastSourceLine = null ;
92
- let lastSourceColumn = null ;
93
-
94
92
for ( let j = 0 ; j < segments . length ; j ++ ) {
95
93
const segment = segments [ j ] ;
96
94
const genCol = segment [ 0 ] ;
@@ -112,19 +110,11 @@ export function traceMappings(tree: MapSource): GenMapping {
112
110
if ( traced == null ) continue ;
113
111
}
114
112
115
- // So we traced a segment down into its original source file. Now push a
116
- // new segment pointing to this location.
117
113
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 ;
124
114
125
115
// 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 ) ;
128
118
}
129
119
}
130
120
0 commit comments