@marko/compiler
Advanced tools
Comparing version 5.30.1 to 5.30.2
@@ -9,11 +9,5 @@ "use strict";exports.__esModule = true;exports.MarkoFile = void 0;var _core = require("@babel/core"); | ||
buildCodeFrameError(node, msg, Error) { | ||
return (0, _buildCodeFrame.buildCodeFrameError)( | ||
this.opts.filename, | ||
this.code, | ||
node.loc, | ||
msg, | ||
Error); | ||
buildCodeFrameError(node, msg) { | ||
return (0, _buildCodeFrame.buildCodeFrameError)(this.opts.filename, this.code, node.loc, msg); | ||
} | ||
}exports.MarkoFile = MarkoFile; |
@@ -5,34 +5,45 @@ "use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.buildCodeFrameError = buildCodeFrameError;var _path = _interopRequireDefault(require("path")); | ||
const CWD = process.cwd(); | ||
const indent = " "; | ||
function buildCodeFrameError( | ||
filename, | ||
code, | ||
loc, | ||
message, | ||
Error = SyntaxError) | ||
{ | ||
const err = new Error(); | ||
const codeFrame = buildCodeFrame(filename, code, loc, message); | ||
class CompileError extends Error { | ||
constructor(filename, code, loc, message) { | ||
super(); | ||
const prettyMessage = buildMessage(code, loc, message); | ||
const prettyFileName = buildFileName(filename, loc); | ||
this.stack = loc ? | ||
`CompileError\n${indent}at ${prettyFileName}\n${prettyMessage.replace( | ||
/^/gm, | ||
indent) | ||
}` : | ||
`CompileError: ${prettyMessage}\n${indent}at ${prettyFileName}`; | ||
err.loc = loc; | ||
err.label = message; | ||
err.stack = ""; // Avoid showing the stack trace for this error. | ||
Object.defineProperties(this, { | ||
loc: { value: loc, enumerable: false, writable: true }, | ||
label: { value: message, enumerable: false, writable: true }, | ||
// Ignore some mutations from Babel. | ||
code: { | ||
enumerable: false, | ||
get() { | ||
return undefined; | ||
}, | ||
set() {} | ||
}, | ||
message: { | ||
enumerable: false, | ||
get() { | ||
return `${prettyFileName}: ${message}`; | ||
}, | ||
set() {} | ||
} | ||
}); | ||
} | ||
} | ||
// Prevent babel from changing our error message. | ||
Object.defineProperty(err, "message", { | ||
get() { | ||
return codeFrame; | ||
}, | ||
set() {} | ||
}); | ||
return err; | ||
function buildCodeFrameError(filename, code, loc, message) { | ||
return new CompileError(filename, code, loc, message); | ||
} | ||
function buildCodeFrame(filename, code, loc, message) { | ||
return `${_kleur.default.cyan(_path.default.relative(CWD, filename))}${ | ||
loc ? | ||
`:${_kleur.default.yellow(loc.start.line)}:${_kleur.default.yellow( | ||
loc.start.column + 1) | ||
}\n\n${(0, _codeFrame.codeFrameColumns)( | ||
function buildMessage(code, loc, message) { | ||
return loc ? | ||
(0, _codeFrame.codeFrameColumns)( | ||
code, | ||
@@ -52,6 +63,13 @@ { | ||
}, | ||
{ highlightCode: true, message }) | ||
}` : | ||
`: ${message}` | ||
{ highlightCode: true, message }) : | ||
message; | ||
} | ||
function buildFileName(filename, loc) { | ||
return `${_kleur.default.cyan(_path.default.relative(CWD, filename))}${ | ||
loc ? | ||
`:${_kleur.default.yellow(loc.start.line)}:${_kleur.default.yellow(loc.start.column + 1)}` : | ||
"" | ||
}`; | ||
} |
@@ -1,3 +0,4 @@ | ||
"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule = true;exports.default = throwAggregateError;var _kleur = _interopRequireDefault(require("kleur")); | ||
"use strict";exports.__esModule = true;exports.default = throwAggregateError;const indent = " "; | ||
const compileErrorPrefix = `SyntaxError\n`; | ||
const compileErrorStackTracePrefix = `${compileErrorPrefix + indent}at `; | ||
function throwAggregateError(errors) { | ||
@@ -11,19 +12,18 @@ switch (errors.length) { | ||
let err; | ||
const message = `${_kleur.default.red("AggregationError:")}\n${errors. | ||
map((err) => err.message). | ||
join("\n\n"). | ||
replace(/^(?!\s*$)/gm, "\t")}\n`; | ||
throw new CompileErrors(errors); | ||
} | ||
if (typeof AggregateError === "function") { | ||
err = new AggregateError(errors, message); | ||
} else { | ||
err = new Error(message); | ||
err.name = "AggregateError"; | ||
err.errors = errors; | ||
class CompileErrors extends Error { | ||
constructor(errors) { | ||
super(); | ||
this.errors = errors; | ||
this.stack = `CompileErrors\n${errors. | ||
map(({ stack }) => { | ||
if (stack.startsWith(compileErrorStackTracePrefix)) { | ||
return stack.slice(compileErrorPrefix.length); | ||
} | ||
return stack.replace(/^(?!\s*$)/gm, " "); | ||
}). | ||
join("\n\n")}`; | ||
} | ||
// Remove the stack trace from the error since it is not useful. | ||
err.stack = ""; | ||
throw err; | ||
} |
{ | ||
"name": "@marko/compiler", | ||
"description": "Marko template to JS compiler.", | ||
"version": "5.30.1", | ||
"version": "5.30.2", | ||
"author": "Dylan Piercey <dpiercey@ebay.com>", | ||
@@ -33,3 +33,3 @@ "bugs": "https://github.com/marko-js/marko/issues/new?template=Bug_report.md", | ||
"devDependencies": { | ||
"@marko/translator-default": "^5.28.1" | ||
"@marko/translator-default": "^5.28.2" | ||
}, | ||
@@ -36,0 +36,0 @@ "files": [ |
434960
10199