Skip to content

Commit

Permalink
Improve map-error.js utility
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoofsKelvin committed Jul 31, 2021
1 parent bda36c9 commit ef40b07
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions map-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ for (const file of fs.readdirSync('./dist')) {

console.log();

const SOURCE_NAME_REGEX = /^\s*at .*? \(.*?[/\\]dist[/\\](\d+\.extension\.js):(\d+):(\d+)\)$/;
const SOURCE_ANOM_REGEX = /^\s*at .*?[/\\]dist[/\\](\d+\.extension\.js):(\d+):(\d+)$/;
const SOURCE_NAME_REGEX = /^\s*at .*? \(.*?[/\\]dist[/\\]((?:\d+\.)?extension\.js):(\d+):(\d+)\)$/;
const SOURCE_ANOM_REGEX = /^\s*at .*?[/\\]dist[/\\]((?:\d+\.)?extension\.js):(\d+):(\d+)$/;

let error = '';
rl.createInterface(process.stdin).on('line', async l => {
Expand All @@ -32,8 +32,17 @@ rl.createInterface(process.stdin).on('line', async l => {
line = parseInt(line);
column = parseInt(column);
const map = await maps[file];
if (!map) throw new Error(`Missing map for '${file}'`);
if (!map) {
stack += ' [MISSING]';
console.log(stack);
continue;
}
const pos = map.originalPositionFor({ line, column });
if (!pos.line) {
stack += ' [MISMAPPED]';
console.log(stack);
continue;
}
const ws = stack.match(/^\s*/)[0];
if (named && pos.name) {
stack = `${ws}at ${pos.name} (${pos.source}:${pos.line}:${pos.column})`;
Expand Down

0 comments on commit ef40b07

Please sign in to comment.