Skip to content

Commit

Permalink
Handle null source maps during line number selection
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Aug 25, 2022
1 parent c37ea84 commit 6b78f49
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/worker/line-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function findTest(locations, declaration) {
const range = (start, end) => Array.from({length: end - start + 1}).fill(start).map((element, index) => element + index);

const translate = (sourceMap, pos) => {
if (sourceMap === undefined) {
if (sourceMap === null) {
return pos;
}

Expand All @@ -88,7 +88,7 @@ export default function lineNumberSelection({file, lineNumbers = []}) {

let locations = parse(file);
let lookedForSourceMap = false;
let sourceMap;
let sourceMap = null;

return () => {
if (!lookedForSourceMap) {
Expand All @@ -98,7 +98,13 @@ export default function lineNumberSelection({file, lineNumbers = []}) {
// Source maps are not available before then.
sourceMap = findSourceMap(file);

if (sourceMap !== undefined) {
if (sourceMap === undefined) {
// Prior to Node.js 18.8.0, the value when a source map could not be found was `undefined`.
// This changed to `null` in <https://github.com/nodejs/node/pull/43875>.
sourceMap = null;
}

if (sourceMap !== null) {
locations = locations.map(({start, end}) => ({
start: translate(sourceMap, start),
end: translate(sourceMap, end),
Expand Down

0 comments on commit 6b78f49

Please sign in to comment.