From 6b78f4938ed04e5e3012eb28d8cbecdf10bbc293 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Thu, 25 Aug 2022 15:11:45 +0200 Subject: [PATCH] Handle `null` source maps during line number selection --- lib/worker/line-numbers.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/worker/line-numbers.js b/lib/worker/line-numbers.js index b7031d49b..4e8013def 100644 --- a/lib/worker/line-numbers.js +++ b/lib/worker/line-numbers.js @@ -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; } @@ -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) { @@ -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 . + sourceMap = null; + } + + if (sourceMap !== null) { locations = locations.map(({start, end}) => ({ start: translate(sourceMap, start), end: translate(sourceMap, end),