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 ({
1818 file : string ,
1919 ...results : swc . Output [ ]
2020 ) : 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 ;
2528
2629 let code = "" ;
2730 let offset = 0 ;
@@ -35,6 +38,11 @@ export default async function ({
3538
3639 consumer . eachMapping ( mapping => {
3740 sources . add ( mapping . source ) ;
41+
42+ if ( map == null ) {
43+ map = initMap ( ) ;
44+ }
45+
3846 map . addMapping ( {
3947 generated : {
4048 line : mapping . generatedLine + offset ,
@@ -50,7 +58,7 @@ export default async function ({
5058
5159 sources . forEach ( source => {
5260 const content = consumer . sourceContentFor ( source , true ) ;
53- if ( content !== null ) {
61+ if ( content !== null && map != null ) {
5462 map . setSourceContent ( source , content ) ;
5563 }
5664 } ) ;
@@ -60,7 +68,7 @@ export default async function ({
6068
6169 return {
6270 code,
63- map : map ,
71+ map : map || undefined ,
6472 } ;
6573 }
6674
You can’t perform that action at this time.
0 commit comments