@@ -3,33 +3,16 @@ import { traceSegment, decodedMappings } from '@jridgewell/trace-mapping';
33
44import type { TraceMap } from '@jridgewell/trace-mapping' ;
55
6- export type SourceMapSegmentObject =
7- | {
8- column : number ;
9- line : number ;
10- name : string ;
11- source : string ;
12- content : string | null ;
13- }
14- | {
15- column : null ;
16- line : null ;
17- name : null ;
18- source : null ;
19- content : null ;
20- } ;
21-
22- const SOURCELESS_MAPPING = {
23- source : null ,
24- column : null ,
25- line : null ,
26- name : null ,
27- content : null ,
6+ export type SourceMapSegmentObject = {
7+ column : number ;
8+ line : number ;
9+ name : string ;
10+ source : string ;
11+ content : string | null ;
2812} ;
29- const EMPTY_SOURCES : Sources [ ] = [ ] ;
3013
3114export type OriginalSource = {
32- map : TraceMap ;
15+ map : null ;
3316 sources : Sources [ ] ;
3417 source : string ;
3518 content : string | null ;
@@ -39,17 +22,37 @@ export type MapSource = {
3922 map : TraceMap ;
4023 sources : Sources [ ] ;
4124 source : string ;
42- content : string | null ;
25+ content : null ;
4326} ;
4427
4528export type Sources = OriginalSource | MapSource ;
4629
47- function Source < M extends TraceMap | null > (
48- map : TraceMap | null ,
30+ const SOURCELESS_MAPPING = /* #__PURE__ */ SegmentObject ( '' , - 1 , - 1 , '' , null ) ;
31+ const EMPTY_SOURCES : Sources [ ] = [ ] ;
32+
33+ function SegmentObject (
34+ source : string ,
35+ line : number ,
36+ column : number ,
37+ name : string ,
38+ content : string | null
39+ ) : SourceMapSegmentObject {
40+ return { source, line, column, name, content } ;
41+ }
42+
43+ function Source ( map : TraceMap , sources : Sources [ ] , source : '' , content : null ) : MapSource ;
44+ function Source (
45+ map : null ,
4946 sources : Sources [ ] ,
5047 source : string ,
5148 content : string | null
52- ) : M extends null ? OriginalSource : MapSource {
49+ ) : OriginalSource ;
50+ function Source (
51+ map : TraceMap | null ,
52+ sources : Sources [ ] ,
53+ source : string | '' ,
54+ content : string | null
55+ ) : Sources {
5356 return {
5457 map,
5558 sources,
@@ -112,8 +115,7 @@ export function traceMappings(tree: MapSource): GenMapping {
112115
113116 const { column, line, name, content, source } = traced ;
114117
115- // Sigh, TypeScript can't figure out source/line/column are either all null, or all non-null...
116- ( maybeAddSegment as any ) ( gen , i , genCol , source , line , column , name ) ;
118+ maybeAddSegment ( gen , i , genCol , source , line , column , name ) ;
117119 if ( source && content != null ) setSourceContent ( gen , source , content ) ;
118120 }
119121 }
@@ -132,7 +134,7 @@ export function originalPositionFor(
132134 name : string
133135) : SourceMapSegmentObject | null {
134136 if ( ! source . map ) {
135- return { column , line, name , source : source . source , content : source . content } ;
137+ return SegmentObject ( source . source , line , column , name , source . content ) ;
136138 }
137139
138140 const segment = traceSegment ( source . map , line , column ) ;
0 commit comments