in src/debugger/sourceMapsCombinator.ts [23:101]
public convert(rawBundleSourcemap: RawSourceMap): RawSourceMap {
// Find user files from bundle files list
const consumers: { [key: string]: SourceMapConsumer } = rawBundleSourcemap.sources.reduce(
(result: { [key: string]: SourceMapConsumer }, file) => {
// Skip files inside node_modules
if (file.includes("node_modules")) return result;
try {
const consumer: SourceMapConsumer | null = this.getSourceMapConsumerFrom(file);
if (consumer) result[file] = consumer;
} finally {
return result;
}
},
{},
);
if (Object.keys(consumers).length === 0) {
// Sourcemaps not found, so return original bundle sourcemap
return rawBundleSourcemap;
}
const generator = new SourceMapGenerator();
const bundleConsumer = new SourceMapConsumer(rawBundleSourcemap);
bundleConsumer.eachMapping((item: MappingItem) => {
if (item.source === null) {
// Some mappings in react native bundle have no sources
return;
}
// Copy mappings
const mapping: Mapping = {
generated: { line: item.generatedLine, column: item.generatedColumn },
original: { line: item.originalLine, column: item.originalColumn },
source: item.source,
name: item.name,
};
if (consumers[item.source]) {
const jsPosition: Position = {
line: item.originalLine,
column: item.originalColumn,
};
const tsPosition: NullableMappedPosition =
consumers[item.source].originalPositionFor(jsPosition);
if (tsPosition.source === null) {
// Some positions from react native generated bundle can not translate to TS source positions
// skip them
return;
}
// Resolve TS source path to absolute because it might be relative to generated JS
// (this depends on whether "sourceRoot" option is specified in tsconfig.json)
if (!tsPosition.source.match(DISK_LETTER_RE)) {
// This check for Windows tests which were run on MacOs
tsPosition.source = path.resolve(
<string>rawBundleSourcemap.sourceRoot,
path.dirname(item.source),
tsPosition.source,
);
}
// Update mapping w/ mapped position values
mapping.source = tsPosition.source;
mapping.name = tsPosition.name || mapping.name;
if (tsPosition.line !== null && tsPosition.column !== null) {
mapping.original = { line: tsPosition.line, column: tsPosition.column };
}
}
try {
generator.addMapping(mapping);
} catch (err) {}
});
return generator.toJSON();
}