Skip to content

Commit

Permalink
fix(sourcemap): fall back to low-resolution line mapping
Browse files Browse the repository at this point in the history
…inside `Link.traceSegment` instead of returning null, so that a low-resolution sourcemap preceding a high-resolution sourcemap in the sourcemap chain doesn't fail.
  • Loading branch information
aleclarson committed Dec 30, 2021
1 parent f9cbd2c commit f9c808b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/utils/collapseSourcemaps.ts
Expand Up @@ -117,6 +117,23 @@ class Link {
const segments = this.mappings[line];
if (!segments) return null;

// Sometimes a high-resolution sourcemap will be preceded in the sourcemap chain
// by a low-resolution sourcemap. We can detect this by checking if the mappings
// array for this line only contains a segment for column zero. In that case, we
// want to fall back to a low-resolution mapping instead of returning null.
if (segments.length == 1 && segments[0][0] == 0) {
const segment = segments[0];
if (segment.length == 1) {
return null;
}
const source = this.sources[segment[1]] || null;
return source?.traceSegment(
segment[2],
segment[3],
segment.length === 5 ? this.names[segment[4]] : name
);
}

// binary search through segments for the given column
let i = 0;
let j = segments.length - 1;
Expand Down

0 comments on commit f9c808b

Please sign in to comment.