Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test: fix up tests; add test for enclosing function
  • Loading branch information
bcoe committed Nov 28, 2020
commit e4695545bc3dcefb9edbdba4e1ec77d1042994c8
4 changes: 3 additions & 1 deletion lib/internal/source_map/prepare_stack_trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ const prepareStackTrace = (globalThis, error, trace) => {
);
}
// Show both original and transpiled stack trace information:
const prefix = name ? `\n -> at ${name}` : '\n ->';
const prefix = (name && name !== t.getFunctionName()) ?
`\n -> at ${name}` :
'\n ->';
const originalSourceNoScheme =
StringPrototypeStartsWith(originalSource, 'file://') ?
fileURLToPath(originalSource) : originalSource;
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/source-map/enclosing-call-site-min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var functionA=function(){functionB()};function functionB(){functionC()}var functionC=function(){functionD()},functionD=function(){if(0<Math.random())throw Error("an error!");},thrower=functionA;try{functionA()}catch(a){throw a;};
//# sourceMappingURL=enclosing-call-site.js.map

27 changes: 27 additions & 0 deletions test/fixtures/source-map/enclosing-call-site.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const functionA = () => {
functionB()
}

function functionB() {
functionC()
}

const functionC = () => {
functionD()
}

const functionD = () => {
(function functionE () {
if (Math.random() > 0) {
throw new Error('an error!')
}
})()
}

const thrower = functionA

try {
thrower()
} catch (err) {
throw err
}
8 changes: 8 additions & 0 deletions test/fixtures/source-map/enclosing-call-site.js.map

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

5 changes: 5 additions & 0 deletions test/message/source_map_enclosing_function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Flags: --enable-source-maps

'use strict';
require('../common');
require('../fixtures/source-map/enclosing-call-site-min.js');
20 changes: 20 additions & 0 deletions test/message/source_map_enclosing_function.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
*enclosing-call-site.js:16
throw new Error('an error!')
^

Error: an error!
at functionD (*enclosing-call-site-min.js:1:156)
-> at functionD (*enclosing-call-site.js:16:17)
at functionC (*enclosing-call-site-min.js:1:97)
-> at functionC (*enclosing-call-site.js:10:3)
at functionB (*enclosing-call-site-min.js:1:60)
-> at functionB (*enclosing-call-site.js:6:3)
at functionA (*enclosing-call-site-min.js:1:26)
-> at functionA (*enclosing-call-site.js:2:3)
at Object.<anonymous> (*enclosing-call-site-min.js:1:199)
-> (*enclosing-call-site.js:24:3)
at Module._compile (node:internal/modules/cjs/loader:*)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*)
at Module.load (node:internal/modules/cjs/loader:*)
at Function.Module._load (node:internal/modules/cjs/loader:*)
at Module.require (node:internal/modules/cjs/loader:*)
4 changes: 2 additions & 2 deletions test/message/source_map_reference_error_tabs.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

ReferenceError: alert is not defined
at Object.<anonymous> (*tabs.coffee:39:5)
-> *tabs.coffee:26:2
-> *tabs.coffee:26:2*
at Object.<anonymous> (*tabs.coffee:53:4)
-> *tabs.coffee:1:14
-> *tabs.coffee:1:14*
at Module._compile (node:internal/modules/cjs/loader:*
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*
at Module.load (node:internal/modules/cjs/loader:*
Expand Down
4 changes: 2 additions & 2 deletions test/message/source_map_throw_catch.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ reachable
^
Error: an exception
at branch (*typescript-throw.js:20:15)
-> *typescript-throw.ts:18:11
-> *typescript-throw.ts:18:11*
at Object.<anonymous> (*typescript-throw.js:26:1)
-> *typescript-throw.ts:24:1
-> *typescript-throw.ts:24:1*
at Module._compile (node:internal/modules/cjs/loader:*)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*)
at Module.load (node:internal/modules/cjs/loader:*)
Expand Down
4 changes: 2 additions & 2 deletions test/message/source_map_throw_first_tick.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ reachable
^
Error: an exception
at branch (*typescript-throw.js:20:15)
-> *typescript-throw.ts:18:11
-> *typescript-throw.ts:18:11*
at Object.<anonymous> (*typescript-throw.js:26:1)
-> *typescript-throw.ts:24:1
-> *typescript-throw.ts:24:1*
at Module._compile (node:internal/modules/cjs/loader:*)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*)
at Module.load (node:internal/modules/cjs/loader:*)
Expand Down
4 changes: 2 additions & 2 deletions test/message/source_map_throw_icu.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

Error: an error
at Object.createElement (*icu.js:5:7)
-> *icu.jsx:3:23
-> *icu.jsx:3:23*
at Object.<anonymous> (*icu.js:8:82)
-> *icu.jsx:9:5
-> *icu.jsx:9:5*
at Module._compile (node:internal/modules/cjs/loader:*
at Object.Module._extensions..js (node:internal/modules/cjs/loader:*
at Module.load (node:internal/modules/cjs/loader:*
Expand Down
4 changes: 2 additions & 2 deletions test/message/source_map_throw_set_immediate.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Error: goodbye
at *uglify-throw.js:1:43
-> *uglify-throw-original.js:5:9
-> at Hello *uglify-throw-original.js:5:9*
at Immediate.<anonymous> (*uglify-throw.js:1:60)
-> *uglify-throw-original.js:9:3
-> *uglify-throw-original.js:9:3*
at processImmediate (node:internal/timers:*)