import { ParserErrorTypes, errorMessages } from './errorTypes' import { Namespace, Namespaces, AttributeNode, CommentNode, DirectiveNode, ElementNode, ElementTypes, ExpressionNode, NodeTypes, Position, RootNode, SourceLocation, TextNode } from './ast' export interface ParserOptions { isVoidTag?: (tag: string) => boolean // e.g. img, br, hr getNamespace?: (tag: string, parent: ElementNode | undefined) => Namespace getTextMode?: (tag: string, ns: Namespace) => TextModes delimiters?: [string, string] // ['{{', '}}'] ignoreSpaces?: boolean // Map to HTML entities. E.g., `{ "amp;": "&" }` // The full set is https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references namedCharacterReferences?: { [name: string]: string | undefined } onError?: (type: ParserErrorTypes, loc: Position) => void } export const defaultParserOptions: Required = { delimiters: [`{{`, `}}`], ignoreSpaces: true, getNamespace: () => Namespaces.HTML, getTextMode: () => TextModes.DATA, isVoidTag: () => false, namedCharacterReferences: {}, onError(code: ParserErrorTypes, loc: Position): void { const error: any = new SyntaxError( `${errorMessages[code]} (${loc.line}:${loc.column})` ) error.code = code error.loc = loc throw error } } export const enum TextModes { // | Elements | Entities | End sign | Inside of DATA, // | ✔ | ✔ | End tags of ancestors | RCDATA, // | ✘ | ✔ | End tag of the parent |