Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sourcemap): fall back to low-resolution line mapping #4334

Merged
merged 6 commits into from Mar 4, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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