Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: source maps filter null prefix #42522

Merged
merged 1 commit into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/internal/source_map/prepare_stack_trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ const prepareStackTrace = (globalThis, error, trace) => {
}
// Construct call site name based on: v8.dev/docs/stack-trace-api:
const fnName = t.getFunctionName() ?? t.getMethodName();
const originalName = `${t.getTypeName() !== 'global' ?
`${t.getTypeName()}.` : ''}${fnName || '<anonymous>'}`;
const typeName = t.getTypeName();
const namePrefix = typeName !== null && typeName !== 'global' ? `${typeName}.` : '';
const originalName = `${namePrefix}${fnName || '<anonymous>'}`;
// The original call site may have a different symbol name
// associated with it, use it:
const prefix = (name && name !== originalName) ?
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/source-map/throw-async.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const message = 'Message ' + Math.random();
export async function Throw() {
throw new Error(message);
}
await Throw();
// To recreate:
//
// npx tsc --module esnext --target es2017 --outDir test/fixtures/source-map --sourceMap test/fixtures/source-map/throw-async.ts
// + rename js to mjs
// + rename js to mjs in source map comment in mjs file
//# sourceMappingURL=throw-async.mjs.map
1 change: 1 addition & 0 deletions test/fixtures/source-map/throw-async.mjs.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions test/fixtures/source-map/throw-async.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const message = 'Message ' + Math.random();

export async function Throw() {
throw new Error(message)
}

await Throw();

// To recreate:
//
// npx tsc --module esnext --target es2017 --outDir test/fixtures/source-map --sourceMap test/fixtures/source-map/throw-async.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the target is es2018 or higher tsc will not down-level transpile async functions - so that'd how you'd test the thing

// + rename js to mjs
// + rename js to mjs in source map comment in mjs file
16 changes: 16 additions & 0 deletions test/parallel/test-source-map-enable.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,22 @@ function nextdir() {
assert.ok(sourceMap);
}

// Does not include null for async/await with esm
// Refs: https://github.com/nodejs/node/issues/42417
{
const output = spawnSync(process.execPath, [
'--enable-source-maps',
require.resolve('../fixtures/source-map/throw-async.mjs'),
]);
// Error in original context of source content:
assert.match(
output.stderr.toString(),
/throw new Error\(message\)\r?\n.*\^/
);
// Rewritten stack trace:
assert.match(output.stderr.toString(), /at Throw \([^)]+throw-async\.ts:4:9\)/);
}

function getSourceMapFromCache(fixtureFile, coverageDirectory) {
const jsonFiles = fs.readdirSync(coverageDirectory);
for (const jsonFile of jsonFiles) {
Expand Down