CompileError
Thrown by compile for source the compiler cannot or refuses to transform.
Thrown by compile for source the compiler cannot or refuses to transform. It carries the
Diagnostic with the position, a printable code frame, and the name of the file. The
message has the form <id>:<line>:<column> <code>: <message> followed by the frame.
Import#
ts
import { CompileError } from "@shadow-js/compiler";
Signature#
ts
class CompileError extends Error
Members#
| Name | Type | Description |
|---|---|---|
diagnostic |
readonly diagnostic: Diagnostic |
The problem: its code, message, severity and position in the original source. |
frame |
readonly frame: string |
Source excerpt of the offending line with a caret under the column, ready to print. |
id |
readonly id: string |
The filename the module was compiled with. |
Examples#
ts
import { CompileError, compile } from "@shadow-js/compiler";
function check(source: string): string | null {
try {
compile(source, { filename: "view.tsx" });
return null;
} catch (error) {
if (!(error instanceof CompileError)) throw error;
return `${error.diagnostic.code} at line ${error.diagnostic.line}`;
}
}
console.log(check("const view = <div>;")); // "PARSE_ERROR at line 1"