als-require
Version:
A utility for using CommonJS require in the browser and creating bundles.
19 lines (18 loc) • 783 B
JavaScript
function parseError(error, modulesLines, curLastLine) {
let [message, ...stack] = error.stack.split('\n')
stack = stack.map(string => {
const m = string.match(/<anonymous>:(\d*):(\d*)\)$/)
if (!m) return
const line = Number(m[1])
if (line + 1 === curLastLine) return
const char = Number(m[2])
const errorLines = Object.entries(modulesLines).filter(([path, { from, to }]) => line >= from && line <= to)
if(errorLines.length === 0) return
const [path, { from, to }] = errorLines[0]
const at = string.match(/at\s(.*?)\s/)[1]
return ` at ${at} ${path} (${line - from - 2}:${char})`
}).filter(Boolean)
error.stack = message + '\n' + stack.join('\n')
throw error
}
module.exports = parseError