Skip to content

Commit f7b84dd

Browse files
committed
refactor: improve stack trace capture in debug.pos function
1 parent c9f05a2 commit f7b84dd

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/debug.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ function emit(data) {
1212
}
1313

1414
function pos(label, color = '33', prefix = '', suffix = '') {
15-
const stack = (new Error()).stack;
16-
let tmp = stack.split('\n');
15+
let err = {};
16+
Error.captureStackTrace(err);
17+
let tmp = err.stack.split('\n');
1718
let local = tmp[3].indexOf('at Object.jump') > -1 ? tmp[4] : tmp[3];
1819
process.stdout.write(`${prefix}\x1b[${color}m${label} ${local.trim()}\x1b[0m${suffix}${os.EOL}`);
1920
}

0 commit comments

Comments
 (0)