UNPKG

4.94 kBTypeScriptView Raw
1import { Dict, Option, PresentArray } from '@glimmer/interfaces';
2import { ParserNodeBuilder } from '../parser';
3import { SourceLocation } from '../source/location';
4import { SourceOffset, SourceSpan } from '../source/span';
5import * as ASTv1 from './api';
6/**
7 * The Parser Builder differentiates from the public builder API by:
8 *
9 * 1. Offering fewer different ways to instantiate nodes
10 * 2. Mandating source locations
11 */
12declare class Builders {
13 pos(line: number, column: number): {
14 line: number;
15 column: number;
16 };
17 blockItself({ body, blockParams, chained, loc, }: {
18 body?: ASTv1.Statement[];
19 blockParams?: string[];
20 chained?: boolean;
21 loc: SourceSpan;
22 }): ASTv1.Block;
23 template({ body, blockParams, loc, }: {
24 body?: ASTv1.Statement[];
25 blockParams?: string[];
26 loc: SourceSpan;
27 }): ASTv1.Template;
28 mustache({ path, params, hash, trusting, loc, strip, }: {
29 path: ASTv1.Expression;
30 params: ASTv1.Expression[];
31 hash: ASTv1.Hash;
32 trusting: boolean;
33 loc: SourceSpan;
34 strip: ASTv1.StripFlags;
35 }): ASTv1.MustacheStatement;
36 block({ path, params, hash, defaultBlock, elseBlock, loc, openStrip, inverseStrip, closeStrip, }: {
37 path: ASTv1.PathExpression | ASTv1.SubExpression;
38 params: ASTv1.Expression[];
39 hash: ASTv1.Hash;
40 defaultBlock: ASTv1.Block;
41 elseBlock?: Option<ASTv1.Block>;
42 loc: SourceSpan;
43 openStrip: ASTv1.StripFlags;
44 inverseStrip: ASTv1.StripFlags;
45 closeStrip: ASTv1.StripFlags;
46 }): ASTv1.BlockStatement;
47 comment(value: string, loc: SourceOffset): ParserNodeBuilder<ASTv1.CommentStatement>;
48 mustacheComment(value: string, loc: SourceSpan): ASTv1.MustacheCommentStatement;
49 concat(parts: PresentArray<ASTv1.TextNode | ASTv1.MustacheStatement>, loc: SourceSpan): ASTv1.ConcatStatement;
50 element({ tag, selfClosing, attrs, blockParams, modifiers, comments, children, loc, }: BuildElementOptions): ASTv1.ElementNode;
51 elementModifier({ path, params, hash, loc, }: {
52 path: ASTv1.PathExpression | ASTv1.SubExpression;
53 params: ASTv1.Expression[];
54 hash: ASTv1.Hash;
55 loc: SourceSpan;
56 }): ASTv1.ElementModifierStatement;
57 attr({ name, value, loc, }: {
58 name: string;
59 value: ASTv1.AttrNode['value'];
60 loc: SourceSpan;
61 }): ASTv1.AttrNode;
62 text({ chars, loc }: {
63 chars: string;
64 loc: SourceSpan;
65 }): ASTv1.TextNode;
66 sexpr({ path, params, hash, loc, }: {
67 path: ASTv1.PathExpression | ASTv1.SubExpression;
68 params: ASTv1.Expression[];
69 hash: ASTv1.Hash;
70 loc: SourceSpan;
71 }): ASTv1.SubExpression;
72 path({ head, tail, loc, }: {
73 head: ASTv1.PathHead;
74 tail: string[];
75 loc: SourceSpan;
76 }): ASTv1.PathExpression;
77 head(head: string, loc: SourceSpan): ASTv1.PathHead;
78 this(loc: SourceSpan): ASTv1.PathHead;
79 atName(name: string, loc: SourceSpan): ASTv1.PathHead;
80 var(name: string, loc: SourceSpan): ASTv1.PathHead;
81 hash(pairs: ASTv1.HashPair[], loc: SourceSpan): ASTv1.Hash;
82 pair({ key, value, loc, }: {
83 key: string;
84 value: ASTv1.Expression;
85 loc: SourceSpan;
86 }): ASTv1.HashPair;
87 literal<T extends ASTv1.Literal>({ type, value, loc, }: {
88 type: T['type'];
89 value: T['value'];
90 loc?: SourceLocation;
91 }): T;
92 undefined(): ASTv1.UndefinedLiteral;
93 null(): ASTv1.NullLiteral;
94 string(value: string, loc: SourceSpan): ASTv1.StringLiteral;
95 boolean(value: boolean, loc: SourceSpan): ASTv1.BooleanLiteral;
96 number(value: number, loc: SourceSpan): ASTv1.NumberLiteral;
97}
98export declare type ElementParts = ['attrs', ...AttrSexp[]] | ['modifiers', ...ModifierSexp[]] | ['body', ...ASTv1.Statement[]] | ['comments', ...ElementComment[]] | ['as', ...string[]] | ['loc', SourceLocation];
99export declare type PathSexp = string | ['path', string, LocSexp?];
100export declare type ModifierSexp = string | [PathSexp, LocSexp?] | [PathSexp, ASTv1.Expression[], LocSexp?] | [PathSexp, ASTv1.Expression[], Dict<ASTv1.Expression>, LocSexp?];
101export declare type AttrSexp = [string, ASTv1.AttrNode['value'] | string, LocSexp?];
102export declare type LocSexp = ['loc', SourceLocation];
103export declare type ElementComment = ASTv1.MustacheCommentStatement | SourceLocation | string;
104export declare type SexpValue = string | ASTv1.Expression[] | Dict<ASTv1.Expression> | LocSexp | PathSexp | undefined;
105export interface BuildElementOptions {
106 tag: string;
107 selfClosing: boolean;
108 attrs: ASTv1.AttrNode[];
109 modifiers: ASTv1.ElementModifierStatement[];
110 children: ASTv1.Statement[];
111 comments: ElementComment[];
112 blockParams: string[];
113 loc: SourceSpan;
114}
115declare const _default: Builders;
116export default _default;
117//# sourceMappingURL=parser-builders.d.ts.map
\No newline at end of file