Skip to content

Commit 9e9d99b

Browse files
committed
util: keep function name for mapped call sites
Signed-off-by: Lazizbek Ergashev <lazerg2@gmail.com>
1 parent aed4eaf commit 9e9d99b

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎lib/util.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,7 @@ function reconstructCallSite(callSite) {
515515
if (!entry?.originalSource) return;
516516
return {
517517
__proto__: null,
518-
// If the name is not found, it is an empty string to match the behavior of `util.getCallSite()`
519-
functionName: entry.name ?? '',
518+
functionName: entry.name ?? callSite.functionName,
520519
scriptName: entry.originalSource,
521520
lineNumber: entry.originalLine + 1,
522521
column: entry.originalColumn + 1,

‎test/fixtures/source-map/get-call-sites-named-mapped.js‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"version": 3,
3+
"sources": ["get-call-sites-named-original.js"],
4+
"names": [],
5+
"mappings": "AAUA"
6+
}

‎test/parallel/test-util-getcallsites-sourcemap.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ const fixtures = require('../common/fixtures');
3939
assert.strictEqual(callSite.columnNumber, 1);
4040
}
4141

42+
// The generated function name is kept when the source map has no name entry
43+
// for the call site.
44+
{
45+
const file = fixtures.path('source-map', 'get-call-sites-named-mapped.js');
46+
const { status, stderr, stdout } = spawnSync(
47+
process.execPath,
48+
['--enable-source-maps', file],
49+
);
50+
assert.strictEqual(status, 0, stderr.toString());
51+
const callSite = JSON.parse(stdout.toString());
52+
assert.ok(
53+
callSite.scriptName.endsWith('get-call-sites-named-original.js'),
54+
`expected original source in scriptName, got "${callSite.scriptName}"`,
55+
);
56+
assert.strictEqual(callSite.functionName, 'foo');
57+
}
58+
4259
// Without --enable-source-maps the generated file path is preserved.
4360
{
4461
const file = fixtures.path('source-map', 'get-call-sites-mapped.js');

0 commit comments

Comments
 (0)