This repository was archived by the owner on Jan 16, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -18,10 +18,13 @@ export default async function ({
18
18
file : string ,
19
19
...results : swc . Output [ ]
20
20
) : Promise < swc . Output > {
21
- const map = new SourceMapGenerator ( {
22
- file,
23
- sourceRoot : swcOptions . sourceRoot ,
24
- } ) ;
21
+ const initMap = ( ) =>
22
+ new SourceMapGenerator ( {
23
+ file,
24
+ sourceRoot : swcOptions . sourceRoot ,
25
+ } ) ;
26
+
27
+ let map : SourceMapGenerator | null = null ;
25
28
26
29
let code = "" ;
27
30
let offset = 0 ;
@@ -35,6 +38,11 @@ export default async function ({
35
38
36
39
consumer . eachMapping ( mapping => {
37
40
sources . add ( mapping . source ) ;
41
+
42
+ if ( map == null ) {
43
+ map = initMap ( ) ;
44
+ }
45
+
38
46
map . addMapping ( {
39
47
generated : {
40
48
line : mapping . generatedLine + offset ,
@@ -50,7 +58,7 @@ export default async function ({
50
58
51
59
sources . forEach ( source => {
52
60
const content = consumer . sourceContentFor ( source , true ) ;
53
- if ( content !== null ) {
61
+ if ( content !== null && map != null ) {
54
62
map . setSourceContent ( source , content ) ;
55
63
}
56
64
} ) ;
@@ -60,7 +68,7 @@ export default async function ({
60
68
61
69
return {
62
70
code,
63
- map : map ,
71
+ map : map || undefined ,
64
72
} ;
65
73
}
66
74
You can’t perform that action at this time.
0 commit comments