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": [] +}