Skip to content

Commit

Permalink
fix: fall back to low resolution mapping in getOriginalLocation
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Feb 13, 2022
1 parent ac2e525 commit eeca9a7
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/utils/getOriginalLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@ export function getOriginalLocation(
let locationFound = false;

if (line !== undefined) {
for (const segment of line) {
if (segment[0] >= location.column) {
if (segment.length === 1) break;
location = {
column: segment[3],
line: segment[2] + 1,
name: segment.length === 5 ? sourcemap.names[segment[4]] : undefined,
source: sourcemap.sources[segment[1]]
};
locationFound = true;
break;
}
// 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 throwing an error.
const segment =
line.length == 1 && line[0][0] == 0
? line[0]
: line.find(segment => segment[0] >= location.column);

if (segment && segment.length !== 1) {
locationFound = true;
location = {
column: segment[3],
line: segment[2] + 1,
name: segment.length === 5 ? sourcemap.names[segment[4]] : undefined,
source: sourcemap.sources[segment[1]]
};
}
}
if (!locationFound) {
Expand Down

0 comments on commit eeca9a7

Please sign in to comment.