| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent eacd65e commit 6ca9c1e
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -515,8 +515,7 @@ function reconstructCallSite(callSite) { | |||
| 515 | 515 | if (!entry?.originalSource) return; | |
| 516 | 516 | return { | |
| 517 | 517 | __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, | ||
| 520 | 519 | scriptName: entry.originalSource, | |
| 521 | 520 | lineNumber: entry.originalLine + 1, | |
| 522 | 521 | column: entry.originalColumn + 1, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,7 @@ | |||
| 1 | + { | ||
| 2 | + "version": 3, | ||
| 3 | + "sources": ["get-call-sites-function-name-original.js"], | ||
| 4 | + "sourcesContent": ["const { getCallSites } = require('node:util'); function foo() { process.stdout.write(JSON.stringify(getCallSites({ sourceMap: true })[0])); } foo();"], | ||
| 5 | + "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", | ||
| 6 | + "names": [] | ||
| 7 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,18 @@ const fixtures = require('../common/fixtures'); | |||
| 39 | 39 | assert.strictEqual(callSite.columnNumber, 1); | |
| 40 | 40 | } | |
| 41 | 41 | ||
| 42 | + // A source map may omit names, so preserve the function name from the call site. | ||
| 43 | + { | ||
| 44 | + const file = fixtures.path('source-map', 'get-call-sites-function-name-mapped.js'); | ||
| 45 | + const { status, stderr, stdout } = spawnSync( | ||
| 46 | + process.execPath, | ||
| 47 | + ['--enable-source-maps', file], | ||
| 48 | + ); | ||
| 49 | + assert.strictEqual(status, 0, stderr.toString()); | ||
| 50 | + const callSite = JSON.parse(stdout.toString()); | ||
| 51 | + assert.strictEqual(callSite.functionName, 'foo'); | ||
| 52 | + } | ||
| 53 | + | ||
| 42 | 54 | // Without --enable-source-maps the generated file path is preserved. | |
| 43 | 55 | { | |
| 44 | 56 | const file = fixtures.path('source-map', 'get-call-sites-mapped.js'); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments