UNPKG

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