diff --git a/lib/internal/source_map/prepare_stack_trace.js b/lib/internal/source_map/prepare_stack_trace.js index 3e4b0825e7b3a5..814ea396f60144 100644 --- a/lib/internal/source_map/prepare_stack_trace.js +++ b/lib/internal/source_map/prepare_stack_trace.js @@ -112,17 +112,12 @@ function serializeJSStackFrame(sm, callSite, callerCallSite) { const typeName = callSite.getTypeName(); const namePrefix = typeName !== null && typeName !== 'global' ? `${typeName}.` : ''; - const originalName = `${namePrefix}${fnName || ''}`; - // 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 || ''}`; + 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 diff --git a/test/fixtures/source-map/output/source_map_throw_class_method.js b/test/fixtures/source-map/output/source_map_throw_class_method.js new file mode 100644 index 00000000000000..c8c4b722a41829 --- /dev/null +++ b/test/fixtures/source-map/output/source_map_throw_class_method.js @@ -0,0 +1,7 @@ +'use strict'; + +// Flags: --enable-source-maps + +require('../../../common'); +Error.stackTraceLimit = 2; +require('../throw-class-method.min.js'); diff --git a/test/fixtures/source-map/output/source_map_throw_class_method.snapshot b/test/fixtures/source-map/output/source_map_throw_class_method.snapshot new file mode 100644 index 00000000000000..102537a9445e99 --- /dev/null +++ b/test/fixtures/source-map/output/source_map_throw_class_method.snapshot @@ -0,0 +1,6 @@ +Trace: This is a test + at Foo.bar (*/test/fixtures/source-map/throw-class-method.js:3:13) + at Object. (*/test/fixtures/source-map/throw-class-method.js:11:5) +Trace: This is a test + at Bar.bar (*/test/fixtures/source-map/throw-class-method.js:3:13) + at Object. (*/test/fixtures/source-map/throw-class-method.js:13:5) diff --git a/test/fixtures/source-map/throw-class-method.js b/test/fixtures/source-map/throw-class-method.js new file mode 100644 index 00000000000000..8b894418d3b41e --- /dev/null +++ b/test/fixtures/source-map/throw-class-method.js @@ -0,0 +1,18 @@ +class Foo { + bar() { + console.trace('This is a test'); + } +} + +class Bar {} +Bar.prototype.bar = Foo.prototype.bar; + +const foo = new Foo(); +foo.bar(); +const bar = Object.create(Bar.prototype); +bar.bar(); + +// 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 diff --git a/test/fixtures/source-map/throw-class-method.min.js b/test/fixtures/source-map/throw-class-method.min.js new file mode 100644 index 00000000000000..2e4cb84a5a8590 --- /dev/null +++ b/test/fixtures/source-map/throw-class-method.min.js @@ -0,0 +1,2 @@ +class Foo{bar(){console.trace("This is a test")}}class Bar{}Bar.prototype.bar=Foo.prototype.bar;const foo=new Foo;foo.bar();const bar=Object.create(Bar.prototype);bar.bar(); +//# sourceMappingURL=throw-class-method.min.js.map \ No newline at end of file diff --git a/test/fixtures/source-map/throw-class-method.min.js.map b/test/fixtures/source-map/throw-class-method.min.js.map new file mode 100644 index 00000000000000..c0a7ae1aa71768 --- /dev/null +++ b/test/fixtures/source-map/throw-class-method.min.js.map @@ -0,0 +1 @@ +{"version":3,"names":["Foo","bar","console","trace","Bar","prototype","foo","Object","create"],"sources":["throw-class-method.js"],"mappings":"AAAA,MAAMA,IACJ,GAAAC,GACEC,QAAQC,MAAM,iBAChB,EAGF,MAAMC,KACNA,IAAIC,UAAUJ,IAAMD,IAAIK,UAAUJ,IAElC,MAAMK,IAAM,IAAIN,IAChBM,IAAIL,MACJ,MAAMA,IAAMM,OAAOC,OAAOJ,IAAIC,WAC9BJ,IAAIA","ignoreList":[]} \ No newline at end of file diff --git a/test/parallel/test-node-output-sourcemaps.mjs b/test/parallel/test-node-output-sourcemaps.mjs index 81c36934ba0f3e..c11c2c36735dae 100644 --- a/test/parallel/test-node-output-sourcemaps.mjs +++ b/test/parallel/test-node-output-sourcemaps.mjs @@ -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' },