comptime.ts
Version:
<div align="center"> <img src="https://raw.githubusercontent.com/feathers-studio/comptime.ts/master/docs/comptime.ts.svg" alt="Hyperactive"> </div>
48 lines • 2.03 kB
JavaScript
import { process } from "./util.js";
export let box = (text, options, skip) => text;
if (!Boolean(process?.env.NO_BOX)) {
try {
if (!process)
throw new Error();
const boxen = (await import("boxen")).default;
const pad = (text) => text.replace(/^.*$/gm, line => " " + line + " ");
box = (text, options, skip) => (skip ? text : boxen(pad(text), options));
}
catch { }
}
export const COMPTIME_ERRORS = {
CT_ERR_GET_EVALUATION: "CT_ERR_GET_EVALUATION",
CT_ERR_SYNTAX_CHECK: "CT_ERR_SYNTAX_CHECK",
CT_ERR_ERASE_TYPES: "CT_ERR_ERASE_TYPES",
CT_ERR_CREATE_FUNCTION: "CT_ERR_CREATE_FUNCTION",
CT_ERR_EVALUATE: "CT_ERR_EVALUATE",
CT_ERR_NO_COMPTIME: "CT_ERR_NO_COMPTIME",
};
export const COMPTIME_ERRORS_MESSAGES = {
[COMPTIME_ERRORS.CT_ERR_GET_EVALUATION]: "An error occurred while attempting to construct the comptime evaluation block.",
[COMPTIME_ERRORS.CT_ERR_SYNTAX_CHECK]: "Syntax error in comptime evaluation block.",
[COMPTIME_ERRORS.CT_ERR_ERASE_TYPES]: "Error occurred while erasing types.",
[COMPTIME_ERRORS.CT_ERR_CREATE_FUNCTION]: "Error occurred while creating a new Function.",
[COMPTIME_ERRORS.CT_ERR_EVALUATE]: "Error occurred while evaluating the expression.",
[COMPTIME_ERRORS.CT_ERR_NO_COMPTIME]: [
"This function must be called in a comptime context, but was called at runtime.",
'Are you missing `with { type: "comptime" }` or a compile-step?\n',
].join("\n\n"),
};
export const getErr = (code, context) => "\n\n" +
box([
context,
box(COMPTIME_ERRORS_MESSAGES[code] + "\nSee: https://comptime.js.org/errors#" + code.toLowerCase(), {}, context ? false : true),
]
.filter(Boolean)
.join("\n\n"), {
title: "Compile Error",
titleAlignment: "right",
}) +
"\n";
export class ComptimeError extends Error {
constructor(code, context, cause) {
super(getErr(code, context), { cause });
}
}
//# sourceMappingURL=errors.js.map