Skip to content
Open
Changes from all commits
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
39 changes: 24 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 <unknown> (${matchNoMethod[2]})`;
}

return line;
})

Expand All @@ -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();
}