edgerender-yatl
Version:
Yet Another Template Language
84 lines (83 loc) • 2.58 kB
TypeScript
import { SAXParser } from 'sax-wasm';
import type { Clause } from './expressions/build';
interface Attribute {
readonly name: string;
readonly value: (Text | Clause)[];
}
export interface TagElement {
readonly type: 'tag';
readonly name: string;
readonly loc: FileLocation;
readonly fragment?: boolean;
readonly set_attributes?: Attribute[];
readonly attributes?: Attribute[];
readonly body?: TemplateElement[];
readonly if?: Clause;
readonly for?: Clause;
readonly for_names?: string[];
readonly for_join?: (Text | Clause)[];
}
interface Prop {
readonly name: string;
readonly value: (Text | Clause)[];
}
export interface ComponentElement {
readonly type: 'component';
readonly name: string;
readonly loc: FileLocation;
readonly props: Prop[];
readonly if?: Clause;
readonly for?: Clause;
readonly for_names?: string[];
readonly for_join?: (Text | Clause)[];
readonly body: TemplateElement[];
readonly children?: TemplateElement[];
readonly comp_file: string;
readonly comp_loc: FileLocation;
}
export declare type TemplateElement = DocType | Text | Clause | TagElement | ComponentElement;
export declare type FileLoader = (path: string) => Promise<ReadableStream>;
export declare type PrepareParserWasm = (parser: SAXParser) => Promise<void>;
export declare function load_template(file_path: string, file_loader: FileLoader, prepare_parser_wasm: PrepareParserWasm): Promise<TemplateElement[]>;
export interface DocType {
readonly type: 'doctype';
readonly doctype: string;
}
export interface Text {
readonly type: 'text';
readonly text: string;
}
interface PropDef {
readonly name: string;
readonly default?: string;
}
interface ComponentReference {
readonly path: string | null;
used: boolean;
}
interface FileLocation {
readonly line: number;
readonly col: number;
}
export interface ComponentDefinition {
readonly props: PropDef[];
readonly body: TempChunk[];
readonly file: string;
readonly loc: FileLocation;
}
interface AttributeDef {
readonly name: string;
readonly set_name?: string;
readonly for_names?: string[];
readonly value: (Text | Clause)[];
}
interface TempElement {
readonly type: 'temp_element';
readonly name: string;
readonly loc: FileLocation;
readonly attributes: AttributeDef[];
readonly body: TempChunk[];
component?: ComponentDefinition | ComponentReference;
}
export declare type TempChunk = DocType | Text | Clause | TempElement;
export {};