Skip to content

Commit d3efe87

Browse files
committed
fixup! src,lib: print source map error source on demand
1 parent 1ef283d commit d3efe87

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ test/message/esm_display_syntax_error.mjs
66
tools/icu
77
tools/lint-md/lint-md.mjs
88
benchmark/tmp
9+
benchmark/fixtures
910
doc/**/*.js
1011
!doc/api_assets/*.js
1112
!.eslintrc.js

benchmark/es/error-stack.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const modPath = require.resolve('../fixtures/simple-error-stack.js');
5+
6+
const bench = common.createBenchmark(main, {
7+
method: ['without-sourcemap', 'sourcemap'],
8+
n: [1e5],
9+
});
10+
11+
function runN(n) {
12+
delete require.cache[modPath];
13+
const mod = require(modPath);
14+
bench.start();
15+
for (let i = 0; i < n; i++) {
16+
mod.simpleErrorStack();
17+
}
18+
bench.end(n);
19+
}
20+
21+
function main({ n, method }) {
22+
switch (method) {
23+
case 'without-sourcemap':
24+
process.setSourceMapsEnabled(false);
25+
runN(n);
26+
break;
27+
case 'sourcemap':
28+
process.setSourceMapsEnabled(true);
29+
runN(n);
30+
break;
31+
default:
32+
throw new Error(`Unexpected method "${method}"`);
33+
}
34+
}

benchmark/fixtures/simple-error-stack.js

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
// Compile with `tsc --inlineSourceMap benchmark/fixtures/simple-error-stack.ts`.
4+
5+
const lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
6+
7+
function simpleErrorStack() {
8+
try {
9+
(lorem as any).BANG();
10+
} catch (e) {
11+
return e.stack;
12+
}
13+
}
14+
15+
export {
16+
simpleErrorStack,
17+
};

0 commit comments

Comments
 (0)