mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
lib: add type names in source mapped stack traces
The type name is determined by the constructor name of the receiver in a call site. PR-URL: https://github.com/nodejs/node/pull/58976 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
7f37d39a87
commit
f33e0fcc83
7 changed files with 48 additions and 9 deletions
|
@ -112,17 +112,12 @@ function serializeJSStackFrame(sm, callSite, callerCallSite) {
|
|||
|
||||
const typeName = callSite.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 mappedName = (name && name !== originalName) ?
|
||||
`${name}` :
|
||||
`${originalName}`;
|
||||
const hasName = !!(name || originalName);
|
||||
const originalName = `${fnName || '<anonymous>'}`;
|
||||
const mappedName = `${namePrefix}${name || originalName}` || '';
|
||||
// Replace the transpiled call site with the original:
|
||||
return `${prefix}${mappedName}${hasName ? ' (' : ''}` +
|
||||
return `${prefix}${mappedName} (` +
|
||||
`${originalSourceNoScheme}:${originalLine + 1}:` +
|
||||
`${originalColumn + 1}${hasName ? ')' : ''}`;
|
||||
`${originalColumn + 1})`;
|
||||
}
|
||||
|
||||
// Transpilers may have removed the original symbol name used in the stack
|
||||
|
|
7
test/fixtures/source-map/output/source_map_throw_class_method.js
vendored
Normal file
7
test/fixtures/source-map/output/source_map_throw_class_method.js
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
// Flags: --enable-source-maps
|
||||
|
||||
require('../../../common');
|
||||
Error.stackTraceLimit = 2;
|
||||
require('../throw-class-method.min.js');
|
6
test/fixtures/source-map/output/source_map_throw_class_method.snapshot
vendored
Normal file
6
test/fixtures/source-map/output/source_map_throw_class_method.snapshot
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
Error: This is a test
|
||||
at Foo.bar (*/test/fixtures/source-map/throw-class-method.js:3:11)
|
||||
at Object.<anonymous> (*/test/fixtures/source-map/throw-class-method.js:12:7)
|
||||
Error: This is a test
|
||||
at Bar.bar (*/test/fixtures/source-map/throw-class-method.js:3:11)
|
||||
at Object.<anonymous> (*/test/fixtures/source-map/throw-class-method.js:19:7)
|
27
test/fixtures/source-map/throw-class-method.js
vendored
Normal file
27
test/fixtures/source-map/throw-class-method.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
class Foo {
|
||||
bar() {
|
||||
throw Error('This is a test');
|
||||
}
|
||||
}
|
||||
|
||||
class Bar {}
|
||||
Bar.prototype.bar = Foo.prototype.bar;
|
||||
|
||||
try {
|
||||
const foo = new Foo();
|
||||
foo.bar();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
try {
|
||||
const bar = Object.create(Bar.prototype);
|
||||
bar.bar();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
// To recreate:
|
||||
//
|
||||
// cd test/fixtures/source-map
|
||||
// npx terser -o throw-class-method.min.js --source-map "url='throw-class-method.min.js.map'" throw-class-method.js
|
2
test/fixtures/source-map/throw-class-method.min.js
vendored
Normal file
2
test/fixtures/source-map/throw-class-method.min.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
class Foo{bar(){throw Error("This is a test")}}class Bar{}Bar.prototype.bar=Foo.prototype.bar;try{const foo=new Foo;foo.bar()}catch(e){console.error(e)}try{const bar=Object.create(Bar.prototype);bar.bar()}catch(e){console.error(e)}
|
||||
//# sourceMappingURL=throw-class-method.min.js.map
|
1
test/fixtures/source-map/throw-class-method.min.js.map
vendored
Normal file
1
test/fixtures/source-map/throw-class-method.min.js.map
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"names":["Foo","bar","Error","Bar","prototype","foo","e","console","error","Object","create"],"sources":["throw-class-method.js"],"mappings":"AAAA,MAAMA,IACJ,GAAAC,GACE,MAAMC,MAAM,iBACd,EAGF,MAAMC,KACNA,IAAIC,UAAUH,IAAMD,IAAII,UAAUH,IAElC,IACE,MAAMI,IAAM,IAAIL,IAChBK,IAAIJ,KACN,CAAE,MAAOK,GACPC,QAAQC,MAAMF,EAChB,CAEA,IACE,MAAML,IAAMQ,OAAOC,OAAOP,IAAIC,WAC9BH,IAAIA,KACN,CAAE,MAAOK,GACPC,QAAQC,MAAMF,EAChB","ignoreList":[]}
|
|
@ -27,6 +27,7 @@ describe('sourcemaps output', { concurrency: !process.env.TEST_PARALLEL }, () =>
|
|||
{ name: 'source-map/output/source_map_sourcemapping_url_string.js' },
|
||||
{ name: 'source-map/output/source_map_throw_async_stack_trace.mjs' },
|
||||
{ name: 'source-map/output/source_map_throw_catch.js' },
|
||||
{ name: 'source-map/output/source_map_throw_class_method.js' },
|
||||
{ name: 'source-map/output/source_map_throw_construct.mjs' },
|
||||
{ name: 'source-map/output/source_map_throw_first_tick.js' },
|
||||
{ name: 'source-map/output/source_map_throw_icu.js' },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue