Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/source_map/source_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ class SourceMap {
sourceColumnNumber += decodeVLQ(stringCharIterator);

let name;
if (!isSeparator(stringCharIterator.peek())) {
if (stringCharIterator.hasNext() &&
!isSeparator(stringCharIterator.peek())) {
nameIndex += decodeVLQ(stringCharIterator);
name = map.names?.[nameIndex];
}
Expand Down
34 changes: 34 additions & 0 deletions test/parallel/test-source-map-trailing-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';
require('../common');
const assert = require('assert');
const { SourceMap } = require('node:module');

// Refs: https://github.com/nodejs/node/issues/63795

// A mapping whose final segment has 4 fields (no name index) must not
// inherit the previous segment's name.
{
const sm = new SourceMap({
version: 3,
sources: ['a.js'],
names: ['foo'],
mappings: 'AAAAA,CAAC',
});

assert.strictEqual(sm.findEntry(0, 0).name, 'foo');
assert.strictEqual(sm.findEntry(0, 1).name, undefined);
}

// A mapping whose final segment legitimately carries a name index must still
// resolve it: the end-of-string guard must not suppress a real trailing name.
{
const sm = new SourceMap({
version: 3,
sources: ['a.js'],
names: ['foo'],
mappings: 'AAAA,CAAAA',
});

assert.strictEqual(sm.findEntry(0, 0).name, undefined);
assert.strictEqual(sm.findEntry(0, 1).name, 'foo');
}
Loading