mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
The mappings parser detects a segment that has only a generated column by peeking at the next character. At the end of the mappings string the peek returns an empty string, which is not a separator, so a final generated-only segment is decoded with phantom zero deltas and inherits the source, line, and column of the segment before it. With --enable-source-maps, stack frames in code after the last mapped segment are then attributed to the last mapped source. Check for the end of the string before reading source fields. Signed-off-by: Jacky Zhao <j.zhao2k19@gmail.com> PR-URL: https://github.com/nodejs/node/pull/66264 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const { SourceMap } = require('node:module');
|
|
|
|
// A segment with only a generated column marks the code after it as unmapped.
|
|
// When it is the last segment of the mappings, it must not inherit the
|
|
// original position of the segment before it.
|
|
const unmapped = {
|
|
originalSource: undefined,
|
|
originalLine: undefined,
|
|
originalColumn: undefined,
|
|
name: undefined,
|
|
};
|
|
|
|
// Trailing unmapped segment on the same line as the last mapped segment.
|
|
{
|
|
const sm = new SourceMap({
|
|
version: 3,
|
|
sources: ['a.js'],
|
|
names: [],
|
|
mappings: 'AAAA,K',
|
|
});
|
|
|
|
assert.deepStrictEqual(sm.findEntry(0, 5), {
|
|
generatedLine: 0,
|
|
generatedColumn: 5,
|
|
...unmapped,
|
|
});
|
|
assert.deepStrictEqual(sm.findOrigin(1, 6), {});
|
|
}
|
|
|
|
// Trailing unmapped segment on a later line.
|
|
{
|
|
const sm = new SourceMap({
|
|
version: 3,
|
|
sources: ['a.js'],
|
|
names: [],
|
|
mappings: 'AAAA;A',
|
|
});
|
|
|
|
assert.deepStrictEqual(sm.findEntry(1, 3), {
|
|
generatedLine: 1,
|
|
generatedColumn: 0,
|
|
...unmapped,
|
|
});
|
|
assert.deepStrictEqual(sm.findOrigin(2, 4), {});
|
|
}
|
|
|
|
// A segment without a name field must not pick up a name from the names array.
|
|
{
|
|
const sm = new SourceMap({
|
|
version: 3,
|
|
sources: ['a.js'],
|
|
names: ['should-not-be-used'],
|
|
mappings: 'AAAA',
|
|
});
|
|
|
|
assert.deepStrictEqual(sm.findEntry(0, 0), {
|
|
generatedLine: 0,
|
|
generatedColumn: 0,
|
|
originalSource: 'a.js',
|
|
originalLine: 0,
|
|
originalColumn: 0,
|
|
name: undefined,
|
|
});
|
|
}
|