GeezerVison is showing github.com — lib: add type names in source mapped stack traces · nodejs/node@a28e5f0
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/source_map/prepare_stack_trace.js +4-9Lines changed: 4 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -112,17 +112,12 @@ function serializeJSStackFrame(sm, callSite, callerCallSite) { |
112 | 112 |
|
113 | 113 | const typeName = callSite.getTypeName(); |
114 | 114 | const namePrefix = typeName !== null && typeName !== 'global' ? `${typeName}.` : ''; |
115 | | - const originalName = `${namePrefix}${fnName || '<anonymous>'}`; |
116 | | - // The original call site may have a different symbol name |
117 | | - // associated with it, use it: |
118 | | - const mappedName = (name && name !== originalName) ? |
119 | | - `${name}` : |
120 | | - `${originalName}`; |
121 | | - const hasName = !!(name || originalName); |
| 115 | + const originalName = `${fnName || '<anonymous>'}`; |
| 116 | + const mappedName = `${namePrefix}${name || originalName}` || ''; |
122 | 117 | // Replace the transpiled call site with the original: |
123 | | - return `${prefix}${mappedName}${hasName ? ' (' : ''}` + |
| 118 | + return `${prefix}${mappedName} (` + |
124 | 119 | `${originalSourceNoScheme}:${originalLine + 1}:` + |
125 | | - `${originalColumn + 1}${hasName ? ')' : ''}`; |
| 120 | + `${originalColumn + 1})`; |
126 | 121 | } |
127 | 122 |
|
128 | 123 | // Transpilers may have removed the original symbol name used in the stack |
|
Collapse file
Copy file name to clipboard +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// Flags: --enable-source-maps |
| 4 | + |
| 5 | +require('../../../common'); |
| 6 | +Error.stackTraceLimit = 2; |
| 7 | +require('../throw-class-method.min.js'); |
Collapse file
Copy file name to clipboard +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +Error: This is a test |
| 2 | + at Foo.bar (*/test/fixtures/source-map/throw-class-method.js:3:11) |
| 3 | + at Object.<anonymous> (*/test/fixtures/source-map/throw-class-method.js:12:7) |
| 4 | +Error: This is a test |
| 5 | + at Bar.bar (*/test/fixtures/source-map/throw-class-method.js:3:11) |
| 6 | + at Object.<anonymous> (*/test/fixtures/source-map/throw-class-method.js:19:7) |
Collapse file
Copy file name to clipboard +27Lines changed: 27 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +class Foo { |
| 2 | + bar() { |
| 3 | + throw Error('This is a test'); |
| 4 | + } |
| 5 | +} |
| 6 | + |
| 7 | +class Bar {} |
| 8 | +Bar.prototype.bar = Foo.prototype.bar; |
| 9 | + |
| 10 | +try { |
| 11 | + const foo = new Foo(); |
| 12 | + foo.bar(); |
| 13 | +} catch (e) { |
| 14 | + console.error(e); |
| 15 | +} |
| 16 | + |
| 17 | +try { |
| 18 | + const bar = Object.create(Bar.prototype); |
| 19 | + bar.bar(); |
| 20 | +} catch (e) { |
| 21 | + console.error(e); |
| 22 | +} |
| 23 | + |
| 24 | +// To recreate: |
| 25 | +// |
| 26 | +// cd test/fixtures/source-map |
| 27 | +// npx terser -o throw-class-method.min.js --source-map "url='throw-class-method.min.js.map'" throw-class-method.js |
Collapse file
Copy file name to clipboardExpand all lines: test/fixtures/source-map/throw-class-method.min.js +2Lines changed: 2 additions & 0 deletions Collapse file
Copy file name to clipboardExpand all lines: test/fixtures/source-map/throw-class-method.min.js.map +1Lines changed: 1 addition & 0 deletions Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-node-output-sourcemaps.mjs +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -27,6 +27,7 @@ describe('sourcemaps output', { concurrency: !process.env.TEST_PARALLEL }, () => |
27 | 27 | { name: 'source-map/output/source_map_sourcemapping_url_string.js' }, |
28 | 28 | { name: 'source-map/output/source_map_throw_async_stack_trace.mjs' }, |
29 | 29 | { name: 'source-map/output/source_map_throw_catch.js' }, |
| 30 | + { name: 'source-map/output/source_map_throw_class_method.js' }, |
30 | 31 | { name: 'source-map/output/source_map_throw_construct.mjs' }, |
31 | 32 | { name: 'source-map/output/source_map_throw_first_tick.js' }, |
32 | 33 | { name: 'source-map/output/source_map_throw_icu.js' }, |
|