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