mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
Signed-off-by: Hiroki Osame <hiroki.osame@gmail.com> PR-URL: https://github.com/nodejs/node/pull/65108 Fixes: https://github.com/nodejs/node/issues/65104 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
65 lines
2.5 KiB
JavaScript
65 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const assert = require('node:assert');
|
|
const { spawnSync } = require('node:child_process');
|
|
const { getCallSites } = require('node:util');
|
|
const fixtures = require('../common/fixtures');
|
|
|
|
// mapCallSite falls back to the original call site when no source map is
|
|
// registered for the current file.
|
|
{
|
|
const withoutMap = getCallSites(1);
|
|
const withMap = getCallSites(1, { sourceMap: true });
|
|
// scriptName must be identical — no source map registered for this test file
|
|
assert.strictEqual(withMap[0].scriptName, withoutMap[0].scriptName);
|
|
// Both calls report the actual line in this file (they differ by one because
|
|
// they are on consecutive source lines, which is expected).
|
|
assert.ok(typeof withMap[0].lineNumber === 'number');
|
|
assert.ok(typeof withMap[0].columnNumber === 'number');
|
|
}
|
|
|
|
// reconstructCallSite remaps call sites to the original source when
|
|
// --enable-source-maps is active and a source map is found.
|
|
{
|
|
const file = fixtures.path('source-map', 'get-call-sites-mapped.js');
|
|
const { status, stderr, stdout } = spawnSync(
|
|
process.execPath,
|
|
['--enable-source-maps', file],
|
|
);
|
|
assert.strictEqual(status, 0, stderr.toString());
|
|
const callSite = JSON.parse(stdout.toString());
|
|
// scriptName should point to the original (unmapped) source file
|
|
assert.ok(
|
|
callSite.scriptName.endsWith('get-call-sites-original.js'),
|
|
`expected original source in scriptName, got "${callSite.scriptName}"`,
|
|
);
|
|
// lineNumber and columnNumber should reflect the original source position
|
|
assert.strictEqual(callSite.lineNumber, 11);
|
|
assert.strictEqual(callSite.columnNumber, 1);
|
|
}
|
|
|
|
// A source map may omit names, so preserve the function name from the call site.
|
|
{
|
|
const file = fixtures.path('source-map', 'get-call-sites-function-name-mapped.js');
|
|
const { status, stderr, stdout } = spawnSync(
|
|
process.execPath,
|
|
['--enable-source-maps', file],
|
|
);
|
|
assert.strictEqual(status, 0, stderr.toString());
|
|
const callSite = JSON.parse(stdout.toString());
|
|
assert.strictEqual(callSite.functionName, 'foo');
|
|
}
|
|
|
|
// Without --enable-source-maps the generated file path is preserved.
|
|
{
|
|
const file = fixtures.path('source-map', 'get-call-sites-mapped.js');
|
|
const { status, stderr, stdout } = spawnSync(process.execPath, [file]);
|
|
assert.strictEqual(status, 0, stderr.toString());
|
|
const callSite = JSON.parse(stdout.toString());
|
|
assert.ok(
|
|
callSite.scriptName.endsWith('get-call-sites-mapped.js'),
|
|
`expected generated file in scriptName, got "${callSite.scriptName}"`,
|
|
);
|
|
}
|