Skip to content

Commit 4ccc1fa

Browse files
authored
Merge pull request #2617 from microsoft/sourcemap-handle-null-sections
Fix sourcemap flattening when encountering null sections
2 parents ea50a10 + d3ad41d commit 4ccc1fa

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

src/debugger/sourceMap.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface ISourceMap extends RawSourceMap {
1212
sections?: ISourceMapSection[];
1313
}
1414
interface 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
}

0 commit comments

Comments
 (0)