Skip to content

Commit 6258055

Browse files
fabiancookjuanarbol
authored andcommitted
lib: source maps filter null prefix
Fixes: #42417 PR-URL: #42522 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0fcb067 commit 6258055

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

lib/internal/source_map/prepare_stack_trace.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ const prepareStackTrace = (globalThis, error, trace) => {
8888
}
8989
// Construct call site name based on: v8.dev/docs/stack-trace-api:
9090
const fnName = t.getFunctionName() ?? t.getMethodName();
91-
const originalName = `${t.getTypeName() !== 'global' ?
92-
`${t.getTypeName()}.` : ''}${fnName || '<anonymous>'}`;
91+
const typeName = t.getTypeName();
92+
const namePrefix = typeName !== null && typeName !== 'global' ? `${typeName}.` : '';
93+
const originalName = `${namePrefix}${fnName || '<anonymous>'}`;
9394
// The original call site may have a different symbol name
9495
// associated with it, use it:
9596
const prefix = (name && name !== originalName) ?
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const message = 'Message ' + Math.random();
2+
export async function Throw() {
3+
throw new Error(message);
4+
}
5+
await Throw();
6+
// To recreate:
7+
//
8+
// npx tsc --module esnext --target es2017 --outDir test/fixtures/source-map --sourceMap test/fixtures/source-map/throw-async.ts
9+
// + rename js to mjs
10+
// + rename js to mjs in source map comment in mjs file
11+
//# sourceMappingURL=throw-async.mjs.map

test/fixtures/source-map/throw-async.mjs.map

+1
Original file line numberDiff line numberDiff line change
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const message = 'Message ' + Math.random();
2+
3+
export async function Throw() {
4+
throw new Error(message)
5+
}
6+
7+
await Throw();
8+
9+
// To recreate:
10+
//
11+
// npx tsc --module esnext --target es2017 --outDir test/fixtures/source-map --sourceMap test/fixtures/source-map/throw-async.ts
12+
// + rename js to mjs
13+
// + rename js to mjs in source map comment in mjs file

test/parallel/test-source-map-enable.js

+16
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,22 @@ function nextdir() {
343343
assert.ok(sourceMap);
344344
}
345345

346+
// Does not include null for async/await with esm
347+
// Refs: https://github.com/nodejs/node/issues/42417
348+
{
349+
const output = spawnSync(process.execPath, [
350+
'--enable-source-maps',
351+
require.resolve('../fixtures/source-map/throw-async.mjs'),
352+
]);
353+
// Error in original context of source content:
354+
assert.match(
355+
output.stderr.toString(),
356+
/throw new Error\(message\)\r?\n.*\^/
357+
);
358+
// Rewritten stack trace:
359+
assert.match(output.stderr.toString(), /at Throw \([^)]+throw-async\.ts:4:9\)/);
360+
}
361+
346362
function getSourceMapFromCache(fixtureFile, coverageDirectory) {
347363
const jsonFiles = fs.readdirSync(coverageDirectory);
348364
for (const jsonFile of jsonFiles) {

0 commit comments

Comments
 (0)