Skip to content
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
13 changes: 4 additions & 9 deletions lib/internal/source_map/prepare_stack_trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

// Flags: --enable-source-maps

require('../../../common');
Error.stackTraceLimit = 2;
require('../throw-class-method.min.js');
Original file line number Diff line number Diff line change
@@ -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 changes: 27 additions & 0 deletions test/fixtures/source-map/throw-class-method.js
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions test/fixtures/source-map/throw-class-method.min.js

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

1 change: 1 addition & 0 deletions test/fixtures/source-map/throw-class-method.min.js.map

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

1 change: 1 addition & 0 deletions test/parallel/test-node-output-sourcemaps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand Down
Loading