File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ interface ISourceMap extends RawSourceMap {
1212 sections ?: ISourceMapSection [ ] ;
1313}
1414interface ISourceMapSection {
15- map : ISourceMap ;
15+ map : ISourceMap | null ;
1616 offset : { column : number ; line : number } ;
1717}
1818
@@ -69,8 +69,11 @@ export class SourceMapUtil {
6969 let sourceMap = < ISourceMap > JSON . parse ( sourceMapBody ) ;
7070
7171 if ( sourceMap . sections ) {
72- // TODO: there is a need to handle value.map == null, make a fake map
73- sourceMap . sections = sourceMap . sections . filter ( value => value . map != null ) ;
72+ // Preserve indexed sourcemap offsets even when Metro emits a null section map.
73+ sourceMap . sections = sourceMap . sections . map ( section => ( {
74+ ...section ,
75+ map : section . map ?? SourceMapUtil . createEmptySourceMap ( ) ,
76+ } ) ) ;
7477
7578 // eslint-disable-next-line @typescript-eslint/no-var-requires
7679 sourceMap = require ( "flatten-source-map" ) ( sourceMap ) ;
@@ -196,4 +199,14 @@ export class SourceMapUtil {
196199 const pathArgs = p . split ( path . sep ) ;
197200 return path . posix . join . apply ( null , pathArgs ) ;
198201 }
202+
203+ private static createEmptySourceMap ( ) : ISourceMap {
204+ return {
205+ version : 3 ,
206+ sources : [ ] ,
207+ names : [ ] ,
208+ mappings : "" ,
209+ file : "" ,
210+ } ;
211+ }
199212}
You can’t perform that action at this time.
0 commit comments