@@ -3,33 +3,16 @@ import { traceSegment, decodedMappings } from '@jridgewell/trace-mapping';
3
3
4
4
import type { TraceMap } from '@jridgewell/trace-mapping' ;
5
5
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 ;
28
12
} ;
29
- const EMPTY_SOURCES : Sources [ ] = [ ] ;
30
13
31
14
export type OriginalSource = {
32
- map : TraceMap ;
15
+ map : null ;
33
16
sources : Sources [ ] ;
34
17
source : string ;
35
18
content : string | null ;
@@ -39,17 +22,37 @@ export type MapSource = {
39
22
map : TraceMap ;
40
23
sources : Sources [ ] ;
41
24
source : string ;
42
- content : string | null ;
25
+ content : null ;
43
26
} ;
44
27
45
28
export type Sources = OriginalSource | MapSource ;
46
29
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 ,
49
46
sources : Sources [ ] ,
50
47
source : string ,
51
48
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 {
53
56
return {
54
57
map,
55
58
sources,
@@ -112,8 +115,7 @@ export function traceMappings(tree: MapSource): GenMapping {
112
115
113
116
const { column, line, name, content, source } = traced ;
114
117
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 ) ;
117
119
if ( source && content != null ) setSourceContent ( gen , source , content ) ;
118
120
}
119
121
}
@@ -132,7 +134,7 @@ export function originalPositionFor(
132
134
name : string
133
135
) : SourceMapSegmentObject | null {
134
136
if ( ! source . map ) {
135
- return { column , line, name , source : source . source , content : source . content } ;
137
+ return SegmentObject ( source . source , line , column , name , source . content ) ;
136
138
}
137
139
138
140
const segment = traceSegment ( source . map , line , column ) ;
0 commit comments