Skip to content

Commit 6b78f49

Browse files
committed
Handle null source maps during line number selection
1 parent c37ea84 commit 6b78f49

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/worker/line-numbers.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function findTest(locations, declaration) {
6161
const range = (start, end) => Array.from({length: end - start + 1}).fill(start).map((element, index) => element + index);
6262

6363
const translate = (sourceMap, pos) => {
64-
if (sourceMap === undefined) {
64+
if (sourceMap === null) {
6565
return pos;
6666
}
6767

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

8989
let locations = parse(file);
9090
let lookedForSourceMap = false;
91-
let sourceMap;
91+
let sourceMap = null;
9292

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

101-
if (sourceMap !== undefined) {
101+
if (sourceMap === undefined) {
102+
// Prior to Node.js 18.8.0, the value when a source map could not be found was `undefined`.
103+
// This changed to `null` in <https://github.com/nodejs/node/pull/43875>.
104+
sourceMap = null;
105+
}
106+
107+
if (sourceMap !== null) {
102108
locations = locations.map(({start, end}) => ({
103109
start: translate(sourceMap, start),
104110
end: translate(sourceMap, end),

0 commit comments

Comments
 (0)