mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
lib: source maps filter null prefix
Fixes: https://github.com/nodejs/node/issues/42417 PR-URL: https://github.com/nodejs/node/pull/42522 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
@@ -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) ?
|
||||
|
||||
11
test/fixtures/source-map/throw-async.mjs
vendored
Normal file
11
test/fixtures/source-map/throw-async.mjs
vendored
Normal file
@@ -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
test/fixtures/source-map/throw-async.mjs.map
vendored
Normal file
1
test/fixtures/source-map/throw-async.mjs.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"throw-async.mjs","sourceRoot":"","sources":["throw-async.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;AAE3C,MAAM,CAAC,KAAK,UAAU,KAAK;IACzB,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;AAC1B,CAAC;AAED,MAAM,KAAK,EAAE,CAAC;AAEd,eAAe;AACf,EAAE;AACF,gIAAgI;AAChI,qBAAqB;AACrB,uDAAuD"}
|
||||
13
test/fixtures/source-map/throw-async.ts
vendored
Normal file
13
test/fixtures/source-map/throw-async.ts
vendored
Normal file
@@ -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
|
||||
// + rename js to mjs
|
||||
// + rename js to mjs in source map comment in mjs file
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user