UNPKG

7.04 kBTypeScriptView Raw
1import type { Nullable, PresentArray } from '@glimmer/interfaces';
2import type * as src from '../source/api';
3export interface BaseNode {
4 type: NodeType;
5 loc: src.SourceSpan;
6}
7export interface CommonProgram extends BaseNode {
8 body: Statement[];
9}
10export interface Block extends CommonProgram {
11 type: 'Block';
12 params: VarHead[];
13 chained?: boolean;
14 /**
15 * string accessor for params.name
16 */
17 blockParams: string[];
18}
19export type EntityEncodingState = 'transformed' | 'raw';
20export interface Template extends CommonProgram {
21 type: 'Template';
22 blockParams: string[];
23}
24/**
25 * @deprecated use Template or Block instead
26 */
27export type Program = Template | Block;
28export type CallableExpression = SubExpression | PathExpression;
29export interface CallParts {
30 path: CallableExpression;
31 params: Expression[];
32 hash: Hash;
33 loc: src.SourceSpan;
34}
35export type CallNode = MustacheStatement | BlockStatement | ElementModifierStatement | SubExpression;
36export interface MustacheStatement extends BaseNode {
37 type: 'MustacheStatement';
38 path: Expression;
39 params: Expression[];
40 hash: Hash;
41 trusting: boolean;
42 strip: StripFlags;
43 /**
44 * @deprecated use trusting instead
45 */
46 escaped: boolean;
47}
48export interface BlockStatement extends BaseNode {
49 type: 'BlockStatement';
50 path: CallableExpression;
51 params: Expression[];
52 hash: Hash;
53 program: Block;
54 inverse?: Nullable<Block>;
55 openStrip: StripFlags;
56 inverseStrip: StripFlags;
57 closeStrip: StripFlags;
58 chained?: boolean;
59}
60export interface ElementModifierStatement extends BaseNode {
61 type: 'ElementModifierStatement';
62 path: CallableExpression;
63 params: Expression[];
64 hash: Hash;
65}
66export interface CommentStatement extends BaseNode {
67 type: 'CommentStatement';
68 value: string;
69}
70export interface MustacheCommentStatement extends BaseNode {
71 type: 'MustacheCommentStatement';
72 value: string;
73}
74export interface ElementNode extends BaseNode {
75 type: 'ElementNode';
76 path: PathExpression;
77 selfClosing: boolean;
78 attributes: AttrNode[];
79 params: VarHead[];
80 modifiers: ElementModifierStatement[];
81 comments: MustacheCommentStatement[];
82 children: Statement[];
83 /**
84 * span for the open tag
85 */
86 openTag: src.SourceSpan;
87 /**
88 * span for the close tag, null for void or self-closing tags
89 */
90 closeTag: Nullable<src.SourceSpan>;
91 /**
92 * string accessor for path.original
93 */
94 tag: string;
95 /**
96 * string accessor for params.name
97 */
98 blockParams: string[];
99}
100export type StatementName = 'MustacheStatement' | 'CommentStatement' | 'BlockStatement' | 'MustacheCommentStatement' | 'TextNode' | 'ElementNode';
101export interface AttrNode extends BaseNode {
102 type: 'AttrNode';
103 name: string;
104 value: AttrValue;
105}
106export type AttrValue = TextNode | MustacheStatement | ConcatStatement;
107export type AttrPart = TextNode | MustacheStatement;
108export interface TextNode extends BaseNode {
109 type: 'TextNode';
110 chars: string;
111}
112export interface ConcatStatement extends BaseNode {
113 type: 'ConcatStatement';
114 parts: PresentArray<TextNode | MustacheStatement>;
115}
116export type ExpressionName = 'SubExpression' | 'PathExpression' | LiteralName;
117export interface SubExpression extends BaseNode {
118 type: 'SubExpression';
119 path: CallableExpression;
120 params: Expression[];
121 hash: Hash;
122}
123export interface ThisHead {
124 type: 'ThisHead';
125 original: 'this';
126 loc: src.SourceSpan;
127}
128export interface AtHead {
129 type: 'AtHead';
130 name: string;
131 loc: src.SourceSpan;
132 /**
133 * alias for name
134 */
135 original: string;
136}
137export interface VarHead {
138 type: 'VarHead';
139 name: string;
140 loc: src.SourceSpan;
141 /**
142 * alias for name
143 */
144 original: string;
145}
146export type PathHead = ThisHead | AtHead | VarHead;
147export interface MinimalPathExpression extends BaseNode {
148 type: 'PathExpression';
149 head: PathHead;
150 tail: string[];
151}
152export interface PathExpression extends MinimalPathExpression {
153 type: 'PathExpression';
154 original: string;
155 head: PathHead;
156 tail: string[];
157 /**
158 * @deprecated use `head` and `tail` instead
159 */
160 parts: readonly string[];
161 /**
162 * @deprecated use `head.type` instead
163 */
164 readonly this: boolean;
165 /**
166 * @deprecated use `head.type' instead
167 */
168 readonly data: boolean;
169}
170export type LiteralName = 'StringLiteral' | 'BooleanLiteral' | 'NumberLiteral' | 'UndefinedLiteral' | 'NullLiteral';
171export interface StringLiteral extends BaseNode {
172 type: 'StringLiteral';
173 value: string;
174 /**
175 * @deprecated use value instead
176 */
177 original: string;
178}
179export interface BooleanLiteral extends BaseNode {
180 type: 'BooleanLiteral';
181 value: boolean;
182 /**
183 * @deprecated use value instead
184 */
185 original: boolean;
186}
187export interface NumberLiteral extends BaseNode {
188 type: 'NumberLiteral';
189 value: number;
190 /**
191 * @deprecated use value instead
192 */
193 original: number;
194}
195export interface UndefinedLiteral extends BaseNode {
196 type: 'UndefinedLiteral';
197 value: undefined;
198 /**
199 * @deprecated use value instead
200 */
201 original: undefined;
202}
203export interface NullLiteral extends BaseNode {
204 type: 'NullLiteral';
205 value: null;
206 /**
207 * @deprecated use value instead
208 */
209 original: null;
210}
211export interface Hash extends BaseNode {
212 type: 'Hash';
213 pairs: HashPair[];
214}
215export interface HashPair extends BaseNode {
216 type: 'HashPair';
217 key: string;
218 value: Expression;
219}
220export interface StripFlags {
221 open: boolean;
222 close: boolean;
223}
224export type Nodes = {
225 Template: Template;
226 Block: Block;
227 MustacheStatement: MustacheStatement;
228 BlockStatement: BlockStatement;
229 ElementModifierStatement: ElementModifierStatement;
230 CommentStatement: CommentStatement;
231 MustacheCommentStatement: MustacheCommentStatement;
232 ElementNode: ElementNode;
233 AttrNode: AttrNode;
234 TextNode: TextNode;
235 ConcatStatement: ConcatStatement;
236 SubExpression: SubExpression;
237 PathExpression: PathExpression;
238 StringLiteral: StringLiteral;
239 BooleanLiteral: BooleanLiteral;
240 NumberLiteral: NumberLiteral;
241 NullLiteral: NullLiteral;
242 UndefinedLiteral: UndefinedLiteral;
243 Hash: Hash;
244 HashPair: HashPair;
245};
246export type NodeType = keyof Nodes;
247export type Node = Nodes[NodeType];
248export type SubNodes = {
249 ThisHead: ThisHead;
250 AtHead: AtHead;
251 VarHead: VarHead;
252};
253export type SubNodeType = keyof SubNodes;
254export type SubNode = SubNodes[SubNodeType];
255export type Statement = Nodes[StatementName];
256export type Statements = Pick<Nodes, StatementName>;
257export type Literal = Nodes[LiteralName];
258export type Expression = Nodes[ExpressionName];
259export type Expressions = Pick<Nodes, ExpressionName>;
260export type TopLevelStatement = Statement | Nodes['Block'];
261export type ParentNode = Template | Block | ElementNode;