UNPKG

4.58 kBTypeScriptView Raw
1import { Option } from '@glimmer/interfaces';
2import { EntityParser, EventedTokenizer } from 'simple-html-tokenizer';
3import { SourcePosition } from './source/location';
4import { Source } from './source/source';
5import { SourceOffset, SourceSpan } from './source/span';
6import * as ASTv1 from './v1/api';
7import * as HBS from './v1/handlebars-ast';
8export declare type ParserNodeBuilder<N extends {
9 loc: SourceSpan;
10}> = Omit<N, 'loc'> & {
11 loc: SourceOffset;
12};
13export declare type Element = ASTv1.Template | ASTv1.Block | ASTv1.ElementNode;
14export interface Tag<T extends 'StartTag' | 'EndTag'> {
15 readonly type: T;
16 name: string;
17 readonly attributes: ASTv1.AttrNode[];
18 readonly modifiers: ASTv1.ElementModifierStatement[];
19 readonly comments: ASTv1.MustacheCommentStatement[];
20 selfClosing: boolean;
21 readonly loc: SourceSpan;
22}
23export interface Attribute {
24 name: string;
25 currentPart: ASTv1.TextNode | null;
26 parts: (ASTv1.MustacheStatement | ASTv1.TextNode)[];
27 isQuoted: boolean;
28 isDynamic: boolean;
29 start: SourceOffset;
30 valueSpan: SourceSpan;
31}
32export declare abstract class Parser {
33 protected elementStack: Element[];
34 private lines;
35 readonly source: Source;
36 currentAttribute: Option<Attribute>;
37 currentNode: Option<Readonly<ParserNodeBuilder<ASTv1.CommentStatement> | ASTv1.TextNode | ParserNodeBuilder<Tag<'StartTag'>> | ParserNodeBuilder<Tag<'EndTag'>>>>;
38 tokenizer: EventedTokenizer;
39 constructor(source: Source, entityParser?: EntityParser, mode?: 'precompile' | 'codemod');
40 offset(): SourceOffset;
41 pos({ line, column }: SourcePosition): SourceOffset;
42 finish<T extends {
43 loc: SourceSpan;
44 }>(node: ParserNodeBuilder<T>): T;
45 abstract Program(node: HBS.Program): HBS.Output<'Program'>;
46 abstract MustacheStatement(node: HBS.MustacheStatement): HBS.Output<'MustacheStatement'>;
47 abstract Decorator(node: HBS.Decorator): HBS.Output<'Decorator'>;
48 abstract BlockStatement(node: HBS.BlockStatement): HBS.Output<'BlockStatement'>;
49 abstract DecoratorBlock(node: HBS.DecoratorBlock): HBS.Output<'DecoratorBlock'>;
50 abstract PartialStatement(node: HBS.PartialStatement): HBS.Output<'PartialStatement'>;
51 abstract PartialBlockStatement(node: HBS.PartialBlockStatement): HBS.Output<'PartialBlockStatement'>;
52 abstract ContentStatement(node: HBS.ContentStatement): HBS.Output<'ContentStatement'>;
53 abstract CommentStatement(node: HBS.CommentStatement): HBS.Output<'CommentStatement'>;
54 abstract SubExpression(node: HBS.SubExpression): HBS.Output<'SubExpression'>;
55 abstract PathExpression(node: HBS.PathExpression): HBS.Output<'PathExpression'>;
56 abstract StringLiteral(node: HBS.StringLiteral): HBS.Output<'StringLiteral'>;
57 abstract BooleanLiteral(node: HBS.BooleanLiteral): HBS.Output<'BooleanLiteral'>;
58 abstract NumberLiteral(node: HBS.NumberLiteral): HBS.Output<'NumberLiteral'>;
59 abstract UndefinedLiteral(node: HBS.UndefinedLiteral): HBS.Output<'UndefinedLiteral'>;
60 abstract NullLiteral(node: HBS.NullLiteral): HBS.Output<'NullLiteral'>;
61 abstract reset(): void;
62 abstract finishData(): void;
63 abstract tagOpen(): void;
64 abstract beginData(): void;
65 abstract appendToData(char: string): void;
66 abstract beginStartTag(): void;
67 abstract appendToTagName(char: string): void;
68 abstract beginAttribute(): void;
69 abstract appendToAttributeName(char: string): void;
70 abstract beginAttributeValue(quoted: boolean): void;
71 abstract appendToAttributeValue(char: string): void;
72 abstract finishAttributeValue(): void;
73 abstract markTagAsSelfClosing(): void;
74 abstract beginEndTag(): void;
75 abstract finishTag(): void;
76 abstract beginComment(): void;
77 abstract appendToCommentData(char: string): void;
78 abstract finishComment(): void;
79 abstract reportSyntaxError(error: string): void;
80 get currentAttr(): Attribute;
81 get currentTag(): ParserNodeBuilder<Tag<'StartTag' | 'EndTag'>>;
82 get currentStartTag(): ParserNodeBuilder<Tag<'StartTag'>>;
83 get currentEndTag(): ParserNodeBuilder<Tag<'EndTag'>>;
84 get currentComment(): ParserNodeBuilder<ASTv1.CommentStatement>;
85 get currentData(): ASTv1.TextNode;
86 acceptTemplate(node: HBS.Program): ASTv1.Template;
87 acceptNode(node: HBS.Program): ASTv1.Block | ASTv1.Template;
88 acceptNode<U extends HBS.Node | ASTv1.Node>(node: HBS.Node): U;
89 currentElement(): Element;
90 sourceForNode(node: HBS.Node, endNode?: {
91 loc: HBS.SourceLocation;
92 }): string;
93}
94//# sourceMappingURL=parser.d.ts.map
\No newline at end of file