From 0821d74838d6b3bf13c75bcf4b7b2a5a225bff14 Mon Sep 17 00:00:00 2001 From: Chirag Bitoni Date: Mon, 9 Nov 2026 02:40:36 +0530 Subject: [PATCH] fix: parse anonymous frame paths with parens and strip async prefix Fix parseLine incorrectly treating paths containing ' (' as function names in anonymous stack frames that lack closing parentheses. Also strip leading 'async ' from anonymous and named async frames. Fixes #76. Signed-off-by: Chirag Bitoni --- index.js | 5 +++++ test/test.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/index.js b/index.js index f567133..9972374 100644 --- a/index.js +++ b/index.js @@ -250,6 +250,9 @@ class StackUtils { } } } + } else if (!closeParen && fname) { + file = `${fname} (${file}`; + fname = undefined; } if (fname) { @@ -317,6 +320,8 @@ const re = new RegExp( '^' + // Sometimes we strip out the ' at' because it's noisy '(?:\\s*at )?' + + // 'async ' prefix on async frames + '(?:async )?' + // $1 = ctor if 'new' '(?:(new) )?' + // $2 = function name (can be literally anything) diff --git a/test/test.js b/test/test.js index 8721f6c..5c3c9df 100644 --- a/test/test.js +++ b/test/test.js @@ -386,6 +386,42 @@ t.test('parseLine: handles parens', t => { t.end(); }); +t.test('parseLine: handles anonymous frames with parens in file path', t => { + const stackUtils = new StackUtils(); + t.same(stackUtils.parseLine(' at /home/me/My App (beta)/index.js:4:11'), { + line: 4, + column: 11, + file: '/home/me/My App (beta)/index.js' + }); + t.same(stackUtils.parseLine(' at C:\\Program Files (x86)\\app\\index.js:4:11'), { + line: 4, + column: 11, + file: 'C:/Program Files (x86)/app/index.js' + }); + t.end(); +}); + +t.test('parseLine: handles async frames', t => { + const stackUtils = new StackUtils(); + t.same(stackUtils.parseLine(' at async /home/me/app/index.js:4:11'), { + line: 4, + column: 11, + file: '/home/me/app/index.js' + }); + t.same(stackUtils.parseLine('async /home/me/app/index.js:4:11'), { + line: 4, + column: 11, + file: '/home/me/app/index.js' + }); + t.same(stackUtils.parseLine(' at async foo (/home/me/app/index.js:4:11)'), { + line: 4, + column: 11, + file: '/home/me/app/index.js', + function: 'foo' + }); + t.end(); +}); + function linuxStack1() { return [ 'Error: foo',