From 7a900e3998a7951a178ef81dab612b5278957159 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 24 Jun 2026 12:16:53 -0600 Subject: [PATCH] fix: add smc.destroy(), handle unmapped lines and bare file:line:col format. SourceMapConsumer was never destroyed, leaking WASM memory and lines with no source map mapping were silently dropped. lines without a method name (file:line:col with trailing space) had leading whitespace in the parsed filenamewhich ended up breaking lookups --- index.js | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index dbd5b65..b02cb5e 100755 --- a/index.js +++ b/index.js @@ -32,7 +32,6 @@ const { file } = cli.flags; const mapPath = cli.input[0]; if (!mapPath) cli.showHelp(); const mapContent = JSON.parse(await readFile(mapPath, 'utf8')); -// WTF? promise? const smc = await new SourceMapConsumer(mapContent); let str; @@ -52,6 +51,12 @@ lines = lines.map((line) => { return `${match[1]}at ${match[3]} (${match[2]})`; } + // handle lines with no method name: ' file:line:col' or ' file:line:col ' + const matchNoMethod = line.match(/^(\s+)([^\s]+:\d+:\d+)\s*$/); + if (matchNoMethod) { + return `${matchNoMethod[1]}at (${matchNoMethod[2]})`; + } + return line; }) @@ -60,19 +65,23 @@ if (stack.length === 0) throw new Error('No stack found'); if (header) console.log(header); -stack.forEach(({ methodName, lineNumber, column }) => { - try { - if (lineNumber == null || lineNumber < 1) { - console.log(` at ${methodName || '[unknown]'}`); - } else { - const pos = smc.originalPositionFor({ line: lineNumber, column }); - if (pos && pos.line != null) { - console.log(` at ${pos.name || methodName || '[unknown]'} (${pos.source}:${pos.line}:${pos.column})`); +try { + stack.forEach(({ methodName, lineNumber, column }) => { + try { + if (lineNumber == null || lineNumber < 1) { + console.log(` at ${methodName || '[unknown]'}`); + } else { + const pos = smc.originalPositionFor({ line: lineNumber, column }); + if (pos && pos.line != null) { + console.log(` at ${pos.name || methodName || '[unknown]'} (${pos.source}:${pos.line}:${pos.column})`); + } else { + console.log(` at ${methodName || '[unknown]'} (line ${lineNumber}:${column})`); + } } - - // console.log('src', smc.sourceContentFor(pos.source)); + } catch (err) { + console.log(` at FAILED_TO_PARSE_LINE`); } - } catch (err) { - console.log(` at FAILED_TO_PARSE_LINE`); - } -}); + }); +} finally { + smc.destroy(); +}