From ed019e4854eb80e7e2358df5d8f0b3d293eca166 Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Fri, 14 Aug 2026 01:13:28 +0900 Subject: [PATCH] util: preserve function names without source map names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hiroki Osame PR-URL: https://github.com/nodejs/node/pull/65108 Fixes: https://github.com/nodejs/node/issues/65104 Reviewed-By: Chengzhong Wu Reviewed-By: Aviv Keller Reviewed-By: Marco Ippolito Signed-off-by: Juan José Arboleda --- lib/util.js | 3 +-- .../source-map/get-call-sites-function-name-mapped.js | 2 ++ .../source-map/get-call-sites-function-name-mapped.map | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/source-map/get-call-sites-function-name-mapped.js create mode 100644 test/fixtures/source-map/get-call-sites-function-name-mapped.map diff --git a/lib/util.js b/lib/util.js index d4a4b458f59..f72cc4209a9 100644 --- a/lib/util.js +++ b/lib/util.js @@ -537,8 +537,7 @@ function reconstructCallSite(callSite) { if (!entry?.originalSource) return; return { __proto__: null, - // If the name is not found, it is an empty string to match the behavior of `util.getCallSite()` - functionName: entry.name ?? '', + functionName: entry.name || callSite.functionName, scriptName: entry.originalSource, lineNumber: entry.originalLine + 1, column: entry.originalColumn + 1, diff --git a/test/fixtures/source-map/get-call-sites-function-name-mapped.js b/test/fixtures/source-map/get-call-sites-function-name-mapped.js new file mode 100644 index 00000000000..d400af7f2fb --- /dev/null +++ b/test/fixtures/source-map/get-call-sites-function-name-mapped.js @@ -0,0 +1,2 @@ +const{getCallSites}=require('node:util');function foo(){process.stdout.write(JSON.stringify(getCallSites({sourceMap:true})[0]))}foo(); +//# sourceMappingURL=get-call-sites-function-name-mapped.map diff --git a/test/fixtures/source-map/get-call-sites-function-name-mapped.map b/test/fixtures/source-map/get-call-sites-function-name-mapped.map new file mode 100644 index 00000000000..de70e4512ff --- /dev/null +++ b/test/fixtures/source-map/get-call-sites-function-name-mapped.map @@ -0,0 +1,7 @@ +{ + "version": 3, + "sources": ["get-call-sites-function-name-original.js"], + "sourcesContent": ["const { getCallSites } = require('node:util'); function foo() { process.stdout.write(JSON.stringify(getCallSites({ sourceMap: true })[0])); } foo();"], + "mappings": "AAAA,KAAM,CAAE,YAAa,EAAI,QAAQ,WAAW,EAAG,SAAS,KAAM,CAAE,QAAQ,OAAO,MAAM,KAAK,UAAU,aAAa,CAAE,UAAW,EAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAG,CAAE,IAAI", + "names": [] +}