UNPKG

8.81 kBTypeScriptView Raw
1import { Dict, Option, PresentArray } from '@glimmer/interfaces';
2export declare type BuilderParams = BuilderExpression[];
3export declare type BuilderHash = Option<Dict<BuilderExpression>>;
4export declare type BuilderBlockHash = BuilderHash | {
5 as: string | string[];
6};
7export declare type BuilderBlocks = Dict<BuilderBlock>;
8export declare type BuilderAttrs = Dict<BuilderAttr>;
9export declare type NormalizedParams = NormalizedExpression[];
10export declare type NormalizedHash = Dict<NormalizedExpression>;
11export declare type NormalizedBlock = NormalizedStatement[];
12export declare type NormalizedBlocks = Dict<NormalizedBlock>;
13export declare type NormalizedAttrs = Dict<NormalizedAttr>;
14export declare type NormalizedAttr = HeadKind.Splat | NormalizedExpression;
15export interface NormalizedElement {
16 name: string;
17 attrs: Option<NormalizedAttrs>;
18 block: Option<NormalizedBlock>;
19}
20export interface NormalizedAngleInvocation {
21 head: NormalizedExpression;
22 attrs: Option<NormalizedAttrs>;
23 block: Option<NormalizedBlock>;
24}
25export declare const enum HeadKind {
26 Block = "Block",
27 Call = "Call",
28 Element = "Element",
29 AppendPath = "AppendPath",
30 AppendExpr = "AppendExpr",
31 Literal = "Literal",
32 Modifier = "Modifier",
33 DynamicComponent = "DynamicComponent",
34 Comment = "Comment",
35 Splat = "Splat",
36 Keyword = "Keyword"
37}
38export declare enum VariableKind {
39 Local = "Local",
40 Free = "Free",
41 Arg = "Arg",
42 Block = "Block",
43 This = "This"
44}
45export interface Variable {
46 kind: VariableKind;
47 name: string;
48 /**
49 * Differences:
50 *
51 * - strict mode variables always refer to in-scope variables
52 * - loose mode variables use this algorithm:
53 * 1. otherwise, fall back to `this.<name>`
54 */
55 mode: 'loose' | 'strict';
56}
57export interface Path {
58 head: Variable;
59 tail: PresentArray<string>;
60}
61export interface AppendExpr {
62 kind: HeadKind.AppendExpr;
63 expr: NormalizedExpression;
64 trusted: boolean;
65}
66export interface AppendPath {
67 kind: HeadKind.AppendPath;
68 path: NormalizedPath;
69 trusted: boolean;
70}
71export interface NormalizedKeywordStatement {
72 kind: HeadKind.Keyword;
73 name: string;
74 params: Option<NormalizedParams>;
75 hash: Option<NormalizedHash>;
76 blockParams: Option<string[]>;
77 blocks: NormalizedBlocks;
78}
79export declare type NormalizedStatement = {
80 kind: HeadKind.Call;
81 head: NormalizedHead;
82 params: Option<NormalizedParams>;
83 hash: Option<NormalizedHash>;
84 trusted: boolean;
85} | {
86 kind: HeadKind.Block;
87 head: NormalizedHead;
88 params: Option<NormalizedParams>;
89 hash: Option<NormalizedHash>;
90 blockParams: Option<string[]>;
91 blocks: NormalizedBlocks;
92} | NormalizedKeywordStatement | {
93 kind: HeadKind.Element;
94 name: string;
95 attrs: NormalizedAttrs;
96 block: NormalizedBlock;
97} | {
98 kind: HeadKind.Comment;
99 value: string;
100} | {
101 kind: HeadKind.Literal;
102 value: string;
103} | AppendPath | AppendExpr | {
104 kind: HeadKind.Modifier;
105 params: NormalizedParams;
106 hash: Option<NormalizedHash>;
107} | {
108 kind: HeadKind.DynamicComponent;
109 expr: NormalizedExpression;
110 hash: Option<NormalizedHash>;
111 block: NormalizedBlock;
112};
113export declare function normalizeStatement(statement: BuilderStatement): NormalizedStatement;
114export declare function normalizeAppendHead(head: NormalizedHead, trusted: boolean): AppendExpr | AppendPath;
115export declare type SugaryArrayStatement = BuilderCallExpression | BuilderElement | BuilderBlockStatement;
116export declare function normalizeSugaryArrayStatement(statement: SugaryArrayStatement): NormalizedStatement;
117export declare function normalizePathHead(whole: string): Variable;
118export declare type BuilderBlockStatement = [string, BuilderBlock | BuilderBlocks] | [string, BuilderParams | BuilderBlockHash, BuilderBlock | BuilderBlocks] | [string, BuilderParams, BuilderBlockHash, BuilderBlock | BuilderBlocks];
119export interface NormalizedBuilderBlockStatement {
120 head: NormalizedHead;
121 params: Option<NormalizedParams>;
122 hash: Option<NormalizedHash>;
123 blockParams: Option<string[]>;
124 blocks: NormalizedBlocks;
125}
126export declare function normalizeBuilderBlockStatement(statement: BuilderBlockStatement): NormalizedBuilderBlockStatement;
127export declare function entries<D extends Dict>(dict: D, callback: <K extends keyof D>(key: K, value: D[K]) => void): void;
128export declare type BuilderElement = [string] | [string, BuilderAttrs, BuilderBlock] | [string, BuilderBlock] | [string, BuilderAttrs];
129export declare type BuilderComment = [Builder.Comment, string];
130export declare type InvocationElement = [string] | [string, BuilderAttrs, BuilderBlock] | [string, BuilderBlock] | [string, BuilderAttrs];
131export declare function isElement(input: [string, ...unknown[]]): input is BuilderElement;
132export declare function extractElement(input: string): Option<string>;
133export declare function extractAngleInvocation(input: string): Option<string>;
134export declare function isAngleInvocation(input: [string, ...unknown[]]): input is InvocationElement;
135export declare function isBlock(input: [string, ...unknown[]]): input is BuilderBlockStatement;
136export declare const enum Builder {
137 Literal = 0,
138 Comment = 1,
139 Append = 2,
140 Modifier = 3,
141 DynamicComponent = 4,
142 Get = 5,
143 Concat = 6,
144 HasBlock = 7,
145 HasBlockParams = 8
146}
147export declare type VerboseStatement = [Builder.Literal, string] | [Builder.Comment, string] | [Builder.Append, BuilderExpression, true] | [Builder.Append, BuilderExpression] | [Builder.Modifier, Params, Hash] | [Builder.DynamicComponent, BuilderExpression, Hash, BuilderBlock];
148export declare type BuilderStatement = VerboseStatement | SugaryArrayStatement | TupleBuilderExpression | string;
149export declare type BuilderAttr = 'splat' | BuilderExpression;
150export declare type TupleBuilderExpression = [Builder.Literal, string | boolean | null | undefined] | [Builder.Get, string] | [Builder.Get, string, string[]] | [Builder.Concat, ...BuilderExpression[]] | [Builder.HasBlock, string] | [Builder.HasBlockParams, string] | BuilderCallExpression;
151declare type Params = BuilderParams;
152declare type Hash = Dict<BuilderExpression>;
153export declare const enum ExpressionKind {
154 Literal = "Literal",
155 Call = "Call",
156 GetPath = "GetPath",
157 GetVar = "GetVar",
158 Concat = "Concat",
159 HasBlock = "HasBlock",
160 HasBlockParams = "HasBlockParams"
161}
162export interface NormalizedCallExpression {
163 type: ExpressionKind.Call;
164 head: NormalizedHead;
165 params: Option<NormalizedParams>;
166 hash: Option<NormalizedHash>;
167}
168export interface NormalizedPath {
169 type: ExpressionKind.GetPath;
170 path: Path;
171}
172export interface NormalizedVar {
173 type: ExpressionKind.GetVar;
174 variable: Variable;
175}
176export declare type NormalizedHead = NormalizedPath | NormalizedVar;
177export interface NormalizedConcat {
178 type: ExpressionKind.Concat;
179 params: [NormalizedExpression, ...NormalizedExpression[]];
180}
181export declare type NormalizedExpression = {
182 type: ExpressionKind.Literal;
183 value: null | undefined | boolean | string | number;
184} | NormalizedCallExpression | NormalizedPath | NormalizedVar | NormalizedConcat | {
185 type: ExpressionKind.HasBlock;
186 name: string;
187} | {
188 type: ExpressionKind.HasBlockParams;
189 name: string;
190};
191export declare function normalizeAppendExpression(expression: BuilderExpression, forceTrusted?: boolean): AppendExpr | AppendPath;
192export declare function normalizeExpression(expression: BuilderExpression): NormalizedExpression;
193export declare type BuilderExpression = TupleBuilderExpression | BuilderCallExpression | null | undefined | boolean | string | number;
194export declare function isBuilderExpression(expr: BuilderExpression | BuilderCallExpression): expr is TupleBuilderExpression | BuilderCallExpression;
195export declare function isLiteral(expr: BuilderExpression | BuilderCallExpression): expr is [Builder.Literal, string | boolean | undefined];
196export declare function statementIsExpression(statement: BuilderStatement): statement is TupleBuilderExpression;
197export declare function isBuilderCallExpression(value: TupleBuilderExpression | BuilderCallExpression): value is BuilderCallExpression;
198export declare type MiniBuilderBlock = BuilderStatement[];
199export declare type BuilderBlock = MiniBuilderBlock;
200export declare type BuilderCallExpression = [string] | [string, Params | Hash] | [string, Params, Hash];
201export declare function normalizeParams(input: Params): NormalizedParams;
202export declare function normalizeHash(input: Option<Hash>): Option<NormalizedHash>;
203export declare function normalizeCallExpression(expr: BuilderCallExpression): NormalizedCallExpression;
204export {};
205//# sourceMappingURL=builder-interface.d.ts.map
\No newline at end of file