1 | import { Nullable, PresentArray, WireFormat, Dict, SerializedTemplateBlock, TemplateJavascript } from "@glimmer/interfaces";
|
2 | import { PrecompileOptions, PrecompileOptionsWithLexicalScope, TemplateIdFn } from "@glimmer/syntax";
|
3 | type BuilderParams = BuilderExpression[];
|
4 | type BuilderHash = Nullable<Dict<BuilderExpression>>;
|
5 | type BuilderBlockHash = BuilderHash | {
|
6 | as: string | string[];
|
7 | };
|
8 | type BuilderBlocks = Dict<BuilderBlock>;
|
9 | type BuilderAttrs = Dict<BuilderAttr>;
|
10 | type NormalizedParams = NormalizedExpression[];
|
11 | type NormalizedHash = Dict<NormalizedExpression>;
|
12 | type NormalizedBlock = NormalizedStatement[];
|
13 | type NormalizedBlocks = Dict<NormalizedBlock>;
|
14 | type NormalizedAttrs = Dict<NormalizedAttr>;
|
15 | type NormalizedAttr = HeadKind.Splat | NormalizedExpression;
|
16 | declare enum HeadKind {
|
17 | Block = "Block",
|
18 | Call = "Call",
|
19 | Element = "Element",
|
20 | AppendPath = "AppendPath",
|
21 | AppendExpr = "AppendExpr",
|
22 | Literal = "Literal",
|
23 | Modifier = "Modifier",
|
24 | DynamicComponent = "DynamicComponent",
|
25 | Comment = "Comment",
|
26 | Splat = "Splat",
|
27 | Keyword = "Keyword"
|
28 | }
|
29 | declare enum VariableKind {
|
30 | Local = "Local",
|
31 | Free = "Free",
|
32 | Arg = "Arg",
|
33 | Block = "Block",
|
34 | This = "This"
|
35 | }
|
36 | interface Variable {
|
37 | kind: VariableKind;
|
38 | name: string;
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | mode: "loose" | "strict";
|
47 | }
|
48 | interface Path {
|
49 | head: Variable;
|
50 | tail: PresentArray<string>;
|
51 | }
|
52 | interface AppendExpr {
|
53 | kind: HeadKind.AppendExpr;
|
54 | expr: NormalizedExpression;
|
55 | trusted: boolean;
|
56 | }
|
57 | interface AppendPath {
|
58 | kind: HeadKind.AppendPath;
|
59 | path: NormalizedPath;
|
60 | trusted: boolean;
|
61 | }
|
62 | interface NormalizedKeywordStatement {
|
63 | kind: HeadKind.Keyword;
|
64 | name: string;
|
65 | params: Nullable<NormalizedParams>;
|
66 | hash: Nullable<NormalizedHash>;
|
67 | blockParams: Nullable<string[]>;
|
68 | blocks: NormalizedBlocks;
|
69 | }
|
70 | type NormalizedStatement = {
|
71 | kind: HeadKind.Call;
|
72 | head: NormalizedHead;
|
73 | params: Nullable<NormalizedParams>;
|
74 | hash: Nullable<NormalizedHash>;
|
75 | trusted: boolean;
|
76 | } | {
|
77 | kind: HeadKind.Block;
|
78 | head: NormalizedHead;
|
79 | params: Nullable<NormalizedParams>;
|
80 | hash: Nullable<NormalizedHash>;
|
81 | blockParams: Nullable<string[]>;
|
82 | blocks: NormalizedBlocks;
|
83 | } | NormalizedKeywordStatement | {
|
84 | kind: HeadKind.Element;
|
85 | name: string;
|
86 | attrs: NormalizedAttrs;
|
87 | block: NormalizedBlock;
|
88 | } | {
|
89 | kind: HeadKind.Comment;
|
90 | value: string;
|
91 | } | {
|
92 | kind: HeadKind.Literal;
|
93 | value: string;
|
94 | } | AppendPath | AppendExpr | {
|
95 | kind: HeadKind.Modifier;
|
96 | params: NormalizedParams;
|
97 | hash: Nullable<NormalizedHash>;
|
98 | } | {
|
99 | kind: HeadKind.DynamicComponent;
|
100 | expr: NormalizedExpression;
|
101 | hash: Nullable<NormalizedHash>;
|
102 | block: NormalizedBlock;
|
103 | };
|
104 | type SugaryArrayStatement = BuilderCallExpression | BuilderElement | BuilderBlockStatement;
|
105 | type BuilderBlockStatement = [
|
106 | string,
|
107 | BuilderBlock | BuilderBlocks
|
108 | ] | [
|
109 | string,
|
110 | BuilderParams | BuilderBlockHash,
|
111 | BuilderBlock | BuilderBlocks
|
112 | ] | [
|
113 | string,
|
114 | BuilderParams,
|
115 | BuilderBlockHash,
|
116 | BuilderBlock | BuilderBlocks
|
117 | ];
|
118 | type BuilderElement = [
|
119 | string
|
120 | ] | [
|
121 | string,
|
122 | BuilderAttrs,
|
123 | BuilderBlock
|
124 | ] | [
|
125 | string,
|
126 | BuilderBlock
|
127 | ] | [
|
128 | string,
|
129 | BuilderAttrs
|
130 | ];
|
131 | type BuilderComment = [
|
132 | Builder.Comment,
|
133 | string
|
134 | ];
|
135 | declare enum Builder {
|
136 | Literal = 0,
|
137 | Comment = 1,
|
138 | Append = 2,
|
139 | Modifier = 3,
|
140 | DynamicComponent = 4,
|
141 | Get = 5,
|
142 | Concat = 6,
|
143 | HasBlock = 7,
|
144 | HasBlockParams = 8
|
145 | }
|
146 | type VerboseStatement = [
|
147 | Builder.Literal,
|
148 | string
|
149 | ] | [
|
150 | Builder.Comment,
|
151 | string
|
152 | ] | [
|
153 | Builder.Append,
|
154 | BuilderExpression,
|
155 | true
|
156 | ] | [
|
157 | Builder.Append,
|
158 | BuilderExpression
|
159 | ] | [
|
160 | Builder.Modifier,
|
161 | Params,
|
162 | Hash
|
163 | ] | [
|
164 | Builder.DynamicComponent,
|
165 | BuilderExpression,
|
166 | Hash,
|
167 | BuilderBlock
|
168 | ];
|
169 | type BuilderStatement = VerboseStatement | SugaryArrayStatement | TupleBuilderExpression | string;
|
170 | type BuilderAttr = "splat" | BuilderExpression;
|
171 | type TupleBuilderExpression = [
|
172 | Builder.Literal,
|
173 | string | boolean | null | undefined
|
174 | ] | [
|
175 | Builder.Get,
|
176 | string
|
177 | ] | [
|
178 | Builder.Get,
|
179 | string,
|
180 | string[]
|
181 | ] | [
|
182 | Builder.Concat,
|
183 | ...BuilderExpression[]
|
184 | ] | [
|
185 | Builder.HasBlock,
|
186 | string
|
187 | ] | [
|
188 | Builder.HasBlockParams,
|
189 | string
|
190 | ] | BuilderCallExpression;
|
191 | type Params = BuilderParams;
|
192 | type Hash = Dict<BuilderExpression>;
|
193 | declare enum ExpressionKind {
|
194 | Literal = "Literal",
|
195 | Call = "Call",
|
196 | GetPath = "GetPath",
|
197 | GetVar = "GetVar",
|
198 | Concat = "Concat",
|
199 | HasBlock = "HasBlock",
|
200 | HasBlockParams = "HasBlockParams"
|
201 | }
|
202 | interface NormalizedCallExpression {
|
203 | type: ExpressionKind.Call;
|
204 | head: NormalizedHead;
|
205 | params: Nullable<NormalizedParams>;
|
206 | hash: Nullable<NormalizedHash>;
|
207 | }
|
208 | interface NormalizedPath {
|
209 | type: ExpressionKind.GetPath;
|
210 | path: Path;
|
211 | }
|
212 | interface NormalizedVar {
|
213 | type: ExpressionKind.GetVar;
|
214 | variable: Variable;
|
215 | }
|
216 | type NormalizedHead = NormalizedPath | NormalizedVar;
|
217 | interface NormalizedConcat {
|
218 | type: ExpressionKind.Concat;
|
219 | params: [
|
220 | NormalizedExpression,
|
221 | ...NormalizedExpression[]
|
222 | ];
|
223 | }
|
224 | type NormalizedExpression = {
|
225 | type: ExpressionKind.Literal;
|
226 | value: null | undefined | boolean | string | number;
|
227 | } | NormalizedCallExpression | NormalizedPath | NormalizedVar | NormalizedConcat | {
|
228 | type: ExpressionKind.HasBlock;
|
229 | name: string;
|
230 | } | {
|
231 | type: ExpressionKind.HasBlockParams;
|
232 | name: string;
|
233 | };
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 | type BuilderExpression = TupleBuilderExpression | BuilderCallExpression | null | undefined | boolean | string | number;
|
240 | type MiniBuilderBlock = BuilderStatement[];
|
241 | type BuilderBlock = MiniBuilderBlock;
|
242 | type BuilderCallExpression = [
|
243 | string
|
244 | ] | [
|
245 | string,
|
246 | Params | Hash
|
247 | ] | [
|
248 | string,
|
249 | Params,
|
250 | Hash
|
251 | ];
|
252 | interface Symbols {
|
253 | top: ProgramSymbols;
|
254 | freeVar(name: string): number;
|
255 | arg(name: string): number;
|
256 | block(name: string): number;
|
257 | local(name: string): number;
|
258 | this(): number;
|
259 | hasLocal(name: string): boolean;
|
260 | child(params: string[]): LocalSymbols;
|
261 | }
|
262 | declare class ProgramSymbols implements Symbols {
|
263 | _freeVariables: string[];
|
264 | _symbols: string[];
|
265 | top: this;
|
266 | toSymbols(): string[];
|
267 | toUpvars(): string[];
|
268 | freeVar(name: string): number;
|
269 | block(name: string): number;
|
270 | arg(name: string): number;
|
271 | local(name: string): never;
|
272 | this(): number;
|
273 | hasLocal(_name: string): false;
|
274 |
|
275 | symbol(name: string): number;
|
276 | child(locals: string[]): LocalSymbols;
|
277 | }
|
278 | declare class LocalSymbols implements Symbols {
|
279 | private parent;
|
280 | private locals;
|
281 | constructor(parent: Symbols, locals: string[]);
|
282 | get paramSymbols(): number[];
|
283 | get top(): ProgramSymbols;
|
284 | freeVar(name: string): number;
|
285 | arg(name: string): number;
|
286 | block(name: string): number;
|
287 | local(name: string): number;
|
288 | this(): number;
|
289 | hasLocal(name: string): boolean;
|
290 | child(locals: string[]): LocalSymbols;
|
291 | }
|
292 | declare function buildStatements(statements: BuilderStatement[], symbols: Symbols): WireFormat.Statement[];
|
293 | declare function buildStatement(normalized: NormalizedStatement, symbols?: Symbols): WireFormat.Statement[];
|
294 | declare function s(arr: TemplateStringsArray, ...interpolated: unknown[]): [
|
295 | Builder.Literal,
|
296 | string
|
297 | ];
|
298 | declare function c(arr: TemplateStringsArray, ...interpolated: unknown[]): BuilderComment;
|
299 | declare function unicode(charCode: string): string;
|
300 | declare const NEWLINE = "\n";
|
301 | declare const defaultId: TemplateIdFn;
|
302 | /*
|
303 | * Compile a string into a template javascript string.
|
304 | *
|
305 | * Example usage:
|
306 | * import { precompile } from '@glimmer/compiler';
|
307 | * import { templateFactory } from 'glimmer-runtime';
|
308 | * let templateJs = precompile("Howdy {{name}}");
|
309 | * let factory = templateFactory(new Function("return " + templateJs)());
|
310 | * let template = factory.create(env);
|
311 | *
|
312 | * @method precompile
|
313 | * @param {string} string a Glimmer template string
|
314 | * @return {string} a template javascript string
|
315 | */
|
316 | declare function precompileJSON(string: Nullable<string>, options?: PrecompileOptions | PrecompileOptionsWithLexicalScope): [
|
317 | block: SerializedTemplateBlock,
|
318 | usedLocals: string[]
|
319 | ];
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 | declare function precompile(source: string, options?: PrecompileOptions | PrecompileOptionsWithLexicalScope): TemplateJavascript;
|
335 | declare class WireFormatDebugger {
|
336 | private upvars;
|
337 | private symbols;
|
338 | constructor([_statements, symbols, _hasEval, upvars]: SerializedTemplateBlock);
|
339 | format(program: SerializedTemplateBlock): unknown;
|
340 | formatOpcode(opcode: WireFormat.Syntax): unknown;
|
341 | private formatCurryType;
|
342 | private formatElementParams;
|
343 | private formatParams;
|
344 | private formatHash;
|
345 | private formatBlocks;
|
346 | private formatBlock;
|
347 | }
|
348 | export { buildStatement, buildStatements, c, NEWLINE, ProgramSymbols, s, unicode, Builder, BuilderStatement, defaultId, precompile, precompileJSON, PrecompileOptions, WireFormatDebugger };
|
349 |
|
\ | No newline at end of file |