From 770f17f49e2bf323bdc26f55f91adfedcbb94e25 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Wed, 7 Oct 2020 21:55:14 -0700 Subject: [PATCH] fix: favor mapping at 0th column (#120) 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. --- lib/source.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/source.js b/lib/source.js index 9ccd22a9..58902287 100644 --- a/lib/source.js +++ b/lib/source.js @@ -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) {