Repository navigation
Description
Version
Node.js v24.22.2, v26.13.0 and v26.13.1
Platform
macOS 15.2, Darwin 24.2.0, arm64.
Subsystem
source_map
What steps will reproduce the bug?
Save as repro.cjs:
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
const dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'node-map-name-')));
const files = {
"a.js": "const out = [];\nfunction run() {\n throw new Error(\"boom\");\n}\nrun.call(null);\n\n//# sourceMappingURL=a.js.map\n",
"a.js.map": "{\"version\":3,\"sources\":[\"a.ts\"],\"sourcesContent\":[\"const out: string[] = [];\\nfunction run(): void {\\n throw new Error(\\\"boom\\\");\\n}\\nrun.call(null);\\n\"],\"names\":[\"out\",\"run\",\"Error\",\"call\"],\"mappings\":\"AAAA,MAAMA,MAAgB,EAAE;AACxB,SAASC;IACP,MAAM,IAAIC,MAAM;AAClB;AACAD,IAAIE,IAAI,CAAC\"}",
"a.ts": "const out: string[] = [];\nfunction run(): void {\n throw new Error(\"boom\");\n}\nrun.call(null);\n"
};
try {
for (const [name, content] of Object.entries(files)) {
fs.writeFileSync(path.join(dir, name), content);
}
for (const mapped of [false, true]) {
const args = mapped ? ['--enable-source-maps', 'a.js'] : ['a.js'];
const result = spawnSync(process.execPath, args, { cwd: dir, encoding: 'utf8' });
if (result.error) throw result.error;
const frame = result.stderr.split('\n').find(line => /^\s+at /.test(line));
if (result.status !== 1 || !frame) throw new Error(result.stderr);
console.log(mapped ? 'mapped:' : 'unmapped:', frame.trim().replaceAll(dir, '<tmp>'));
}
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}Run:
node repro.cjsHow often does it reproduce? Is there a required condition?
Every run with the embedded source map. The script compares the same generated JavaScript with and without --enable-source-maps.
What is the expected behavior? Why is that the expected behavior?
unmapped: at run (<tmp>/a.js:3:11)
mapped: at run (<tmp>/a.ts:3:9)
The generated function is still named run; the call property belongs to the caller expression run.call(null), not to the function throwing the error. Mapping the location to a.ts should not replace this known name with call. This is a stack-name recovery inconsistency, not a claim that ECMAScript specifies a particular stack-string format. ECMA-426 permits named mappings at expression identifiers, so such a mapping alone does not identify an enclosing function.
What do you see instead?
The listed versions produce:
unmapped: at run (<tmp>/a.js:3:11)
mapped: at call (<tmp>/a.ts:3:9)
Additional information
The fixed fixture was generated using @swc/core 1.16.22 with TypeScript parsing, target=esnext and sourceMaps=true; it is embedded so reproduction needs no compiler. The getOriginalSymbolName fallback uses a caller-site name when the enclosing-function mapping has none. #65108 addresses missing names in util.getCallSites, whereas this example selects the wrong nonempty name. replaces the temporary directory in the output.
AI tools assisted with analysis and preparation of this report and its reproduction. A human has reviewed and confirmed the issue and verified that it is reproducible.
Credit: UCSB PLSE — https://ucsbplse.github.io/
Activity