@marko/compiler
Version:
Marko template to JS compiler.
42 lines (37 loc) • 1.09 kB
JavaScript
;exports.__esModule = true;exports.default = throwAggregateError;var _stripAnsi = require("./strip-ansi");
const indent = " ";
const compileErrorPrefix = `CompileError: \n`;
const compileErrorStackTracePrefix = `${compileErrorPrefix + indent}at `;
function throwAggregateError(errors) {
switch (errors.length) {
case 0:
return;
case 1:
throw errors[0];
}
throw new CompileErrors(errors);
}
class CompileErrors extends Error {
constructor(errors) {
const message = `\n${errors.
map(({ stack }) => {
if (stack.startsWith(compileErrorStackTracePrefix)) {
return stack.slice(compileErrorPrefix.length);
}
return stack.replace(/^(?!\s*$)/gm, " ");
}).
join("\n\n")}`;
const { stackTraceLimit } = Error;
Error.stackTraceLimit = 0;
super(message);
this.name = "CompileErrors";
this.errors = errors;
Error.stackTraceLimit = stackTraceLimit;
}
toJSON() {
return this.toString();
}
toString() {
return `${this.name}: ${(0, _stripAnsi.stripAnsi)(this.message)}`;
}
}