JavaScript API

ErrorSource

A source location attached to CompileError and PluginError.

ErrorSource is the shared source-location type attached to different errors. It carries a file name, the source text, and a Span.

import type { Span } from "telarel";
import { ErrorSource } from "telarel";

Span is { start, end } in UTF-16 code-unit offsets into the source text.

ErrorSource

class ErrorSource {
    constructor(file: string, code: string, span: Span);

    static fromCode(file: string, code: string, span: Span): ErrorSource;
    static fromAst(file: string, ast: Ast, span: Span): ErrorSource;

    get file(): string;
    get code(): string;
    get span(): Span;
}

Use fromCode with a hook's code or fromAst with an Ast whose source text is available.

MemberDescription
fromCodeCreates a location from a file name, its code, and a span.
fromAstCreates a location that shares the AST's source text.
fileThe file the span belongs to.
codeThe source text the span refers to.
spanA copy of the span within code.

span returns a copy, so mutating the result does not mutate the source.

Use CompileError.render() or PluginError.render() to turn a source into a code frame.

Last updated on

Copyright © 2026, Alpheus

On this page