Skip to content

Commit

Permalink
fix: favor mapping at 0th column (#120)
Browse files Browse the repository at this point in the history
If the line reported at the 0th column is greater than the line reported at the calculated column, favor the line at the 0th column.
  • Loading branch information
bcoe committed Oct 8, 2020
1 parent abe51ea commit 770f17f
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions lib/source.js
Expand Up @@ -171,20 +171,39 @@ function originalEndPositionFor (sourceMap, line, column) {
}

function originalPositionTryBoth (sourceMap, line, column) {
const original = sourceMap.originalPositionFor({
let original = sourceMap.originalPositionFor({
line,
column,
bias: GREATEST_LOWER_BOUND
})
if (original.line === null) {
return sourceMap.originalPositionFor({
original = sourceMap.originalPositionFor({
line,
column,
bias: LEAST_UPPER_BOUND
})
} else {
return original
}
// The source maps generated by https://github.com/istanbuljs/istanbuljs
// (using @babel/core 7.7.5) have behavior, such that a mapping
// mid-way through a line maps to an earlier line than a mapping
// at position 0. Using the line at positon 0 seems to provide better reports:
//
// if (true) {
// cov_y5divc6zu().b[1][0]++;
// cov_y5divc6zu().s[3]++;
// console.info('reachable');
// } else { ... }
// ^ ^
// l5 l3
const min = sourceMap.originalPositionFor({
line,
column: 0,
bias: GREATEST_LOWER_BOUND
})
if (min.line > original.line) {
original = min
}
return original
}

function getShebangLength (source) {
Expand Down

0 comments on commit 770f17f

Please sign in to comment.