1 | import type { PresentArray } from '../../array.js';
|
2 | import type { Nullable } from '../../core.js';
|
3 | import type { CurriedType } from '../../curry.js';
|
4 | import type {
|
5 | AppendOpcode,
|
6 | AttrOpcode,
|
7 | AttrSplatOpcode,
|
8 | BlockOpcode,
|
9 | CallOpcode,
|
10 | CloseElementOpcode,
|
11 | CommentOpcode,
|
12 | ComponentAttrOpcode,
|
13 | ComponentOpcode,
|
14 | ConcatOpcode,
|
15 | CurryOpcode,
|
16 | DebuggerOpcode,
|
17 | DynamicArgOpcode,
|
18 | DynamicAttrOpcode,
|
19 | EachOpcode,
|
20 | FlushElementOpcode,
|
21 | GetDynamicVarOpcode,
|
22 | GetFreeAsComponentHeadOpcode,
|
23 | GetFreeAsComponentOrHelperHeadOpcode,
|
24 | GetFreeAsHelperHeadOpcode,
|
25 | GetFreeAsModifierHeadOpcode,
|
26 | GetLexicalSymbolOpcode,
|
27 | GetStrictKeywordOpcode,
|
28 | GetSymbolOpcode,
|
29 | HasBlockOpcode,
|
30 | HasBlockParamsOpcode,
|
31 | IfInlineOpcode,
|
32 | IfOpcode,
|
33 | InElementOpcode,
|
34 | InvokeComponentOpcode,
|
35 | LetOpcode,
|
36 | LogOpcode,
|
37 | ModifierOpcode,
|
38 | NotOpcode,
|
39 | OpenElementOpcode,
|
40 | OpenElementWithSplatOpcode,
|
41 | StaticArgOpcode,
|
42 | StaticAttrOpcode,
|
43 | StaticComponentAttrOpcode,
|
44 | TrustingAppendOpcode,
|
45 | TrustingComponentAttrOpcode,
|
46 | TrustingDynamicAttrOpcode,
|
47 | UndefinedOpcode,
|
48 | WithDynamicVarsOpcode,
|
49 | YieldOpcode,
|
50 | } from './opcodes.js';
|
51 |
|
52 | export * from './opcodes.js';
|
53 | export * from './resolution.js';
|
54 |
|
55 | export type TupleSyntax = Statement | TupleExpression;
|
56 |
|
57 | export type TemplateReference = Nullable<SerializedBlock>;
|
58 | export type YieldTo = number;
|
59 |
|
60 | export type StatementSexpOpcode = Statement[0];
|
61 | export type StatementSexpOpcodeMap = {
|
62 | [TSexpOpcode in Statement[0]]: Extract<Statement, { 0: TSexpOpcode }>;
|
63 | };
|
64 | export type ExpressionSexpOpcode = TupleExpression[0];
|
65 | export type ExpressionSexpOpcodeMap = {
|
66 | [TSexpOpcode in TupleExpression[0]]: Extract<TupleExpression, { 0: TSexpOpcode }>;
|
67 | };
|
68 |
|
69 | export interface SexpOpcodeMap extends ExpressionSexpOpcodeMap, StatementSexpOpcodeMap {}
|
70 | export type SexpOpcode = keyof SexpOpcodeMap;
|
71 |
|
72 | export namespace Core {
|
73 | export type Expression = Expressions.Expression;
|
74 |
|
75 | export type CallArgs = [Params, Hash];
|
76 | export type Path = [string, ...string[]];
|
77 | export type ConcatParams = PresentArray<Expression>;
|
78 | export type Params = Nullable<ConcatParams>;
|
79 | export type Hash = Nullable<[PresentArray<string>, PresentArray<Expression>]>;
|
80 | export type Blocks = Nullable<[string[], SerializedInlineBlock[]]>;
|
81 | export type Args = [Params, Hash];
|
82 | export type NamedBlock = [string, SerializedInlineBlock];
|
83 | export type DebugInfo = number[];
|
84 | export type ElementParameters = Nullable<PresentArray<ElementParameter>>;
|
85 |
|
86 | export type Syntax = Path | Params | ConcatParams | Hash | Blocks | Args | DebugInfo;
|
87 | }
|
88 |
|
89 | export type CoreSyntax = Core.Syntax;
|
90 |
|
91 | export namespace Expressions {
|
92 | export type Path = Core.Path;
|
93 | export type Params = Core.Params;
|
94 | export type Hash = Core.Hash;
|
95 |
|
96 | export type GetSymbol = [GetSymbolOpcode, number];
|
97 | export type GetLexicalSymbol = [GetLexicalSymbolOpcode, number];
|
98 | export type GetStrictFree = [GetStrictKeywordOpcode, number];
|
99 | export type GetFreeAsComponentOrHelperHead = [GetFreeAsComponentOrHelperHeadOpcode, number];
|
100 | export type GetFreeAsHelperHead = [GetFreeAsHelperHeadOpcode, number];
|
101 | export type GetFreeAsModifierHead = [GetFreeAsModifierHeadOpcode, number];
|
102 | export type GetFreeAsComponentHead = [GetFreeAsComponentHeadOpcode, number];
|
103 |
|
104 | export type GetContextualFree =
|
105 | | GetFreeAsComponentOrHelperHead
|
106 | | GetFreeAsHelperHead
|
107 | | GetFreeAsModifierHead
|
108 | | GetFreeAsComponentHead;
|
109 | export type GetFree = GetStrictFree | GetContextualFree;
|
110 | export type GetVar = GetSymbol | GetLexicalSymbol | GetFree;
|
111 |
|
112 | export type GetPathSymbol = [GetSymbolOpcode, number, Path];
|
113 | export type GetPathTemplateSymbol = [GetLexicalSymbolOpcode, number, Path];
|
114 | export type GetPathFreeAsComponentOrHelperHead = [
|
115 | GetFreeAsComponentOrHelperHeadOpcode,
|
116 | number,
|
117 | Path,
|
118 | ];
|
119 | export type GetPathFreeAsHelperHead = [GetFreeAsHelperHeadOpcode, number, Path];
|
120 | export type GetPathFreeAsModifierHead = [GetFreeAsModifierHeadOpcode, number, Path];
|
121 | export type GetPathFreeAsComponentHead = [GetFreeAsComponentHeadOpcode, number, Path];
|
122 |
|
123 | export type GetPathContextualFree =
|
124 | | GetPathFreeAsComponentOrHelperHead
|
125 | | GetPathFreeAsHelperHead
|
126 | | GetPathFreeAsModifierHead
|
127 | | GetPathFreeAsComponentHead;
|
128 | export type GetPath = GetPathSymbol | GetPathTemplateSymbol | GetPathContextualFree;
|
129 |
|
130 | export type Get = GetVar | GetPath;
|
131 |
|
132 | export type StringValue = string;
|
133 | export type NumberValue = number;
|
134 | export type BooleanValue = boolean;
|
135 | export type NullValue = null;
|
136 | export type Value = StringValue | NumberValue | BooleanValue | NullValue;
|
137 | export type Undefined = [UndefinedOpcode];
|
138 |
|
139 | export type TupleExpression =
|
140 | | Get
|
141 | | GetDynamicVar
|
142 | | Concat
|
143 | | HasBlock
|
144 | | HasBlockParams
|
145 | | Curry
|
146 | | Helper
|
147 | | Undefined
|
148 | | IfInline
|
149 | | Not
|
150 | | Log;
|
151 |
|
152 |
|
153 |
|
154 | export type Expression = TupleExpression | Value | undefined;
|
155 |
|
156 | export type Concat = [ConcatOpcode, Core.ConcatParams];
|
157 | export type Helper = [CallOpcode, Expression, Nullable<Params>, Hash];
|
158 | export type HasBlock = [HasBlockOpcode, Expression];
|
159 | export type HasBlockParams = [HasBlockParamsOpcode, Expression];
|
160 | export type Curry = [CurryOpcode, Expression, CurriedType, Params, Hash];
|
161 |
|
162 | export type IfInline = [
|
163 | op: IfInlineOpcode,
|
164 | condition: Expression,
|
165 | truthyValue: Expression,
|
166 | falsyValue?: Nullable<Expression>,
|
167 | ];
|
168 |
|
169 | export type Not = [op: NotOpcode, value: Expression];
|
170 |
|
171 | export type GetDynamicVar = [op: GetDynamicVarOpcode, value: Expression];
|
172 |
|
173 | export type Log = [op: LogOpcode, positional: Params];
|
174 | }
|
175 |
|
176 | export type Expression = Expressions.Expression;
|
177 | export type Get = Expressions.GetVar;
|
178 |
|
179 | export type TupleExpression = Expressions.TupleExpression;
|
180 |
|
181 | export type ClassAttr = 0;
|
182 | export type IdAttr = 1;
|
183 | export type ValueAttr = 2;
|
184 | export type NameAttr = 3;
|
185 | export type TypeAttr = 4;
|
186 | export type StyleAttr = 5;
|
187 | export type HrefAttr = 6;
|
188 |
|
189 | export type WellKnownAttrName =
|
190 | | ClassAttr
|
191 | | IdAttr
|
192 | | ValueAttr
|
193 | | NameAttr
|
194 | | TypeAttr
|
195 | | StyleAttr
|
196 | | HrefAttr;
|
197 |
|
198 | export type DivTag = 0;
|
199 | export type SpanTag = 1;
|
200 | export type PTag = 2;
|
201 | export type ATag = 3;
|
202 |
|
203 | export type WellKnownTagName = DivTag | SpanTag | PTag | ATag;
|
204 |
|
205 | export namespace Statements {
|
206 | export type Expression = Expressions.Expression | undefined;
|
207 | export type Params = Core.Params;
|
208 | export type Hash = Core.Hash;
|
209 | export type Blocks = Core.Blocks;
|
210 | export type Path = Core.Path;
|
211 |
|
212 | export type Append = [AppendOpcode, Expression];
|
213 | export type TrustingAppend = [TrustingAppendOpcode, Expression];
|
214 | export type Comment = [CommentOpcode, string];
|
215 | export type Modifier = [ModifierOpcode, Expression, Params, Hash];
|
216 | export type Block = [BlockOpcode, Expression, Params, Hash, Blocks];
|
217 | export type Component = [
|
218 | op: ComponentOpcode,
|
219 | tag: Expression,
|
220 | parameters: Core.ElementParameters,
|
221 | args: Hash,
|
222 | blocks: Blocks,
|
223 | ];
|
224 | export type OpenElement = [OpenElementOpcode, string | WellKnownTagName];
|
225 | export type OpenElementWithSplat = [OpenElementWithSplatOpcode, string | WellKnownTagName];
|
226 | export type FlushElement = [FlushElementOpcode];
|
227 | export type CloseElement = [CloseElementOpcode];
|
228 |
|
229 | type Attr<Op extends AttrOpcode> = [
|
230 | op: Op,
|
231 | name: string | WellKnownAttrName,
|
232 | value: Expression,
|
233 | namespace?: string | undefined,
|
234 | ];
|
235 |
|
236 | export type StaticAttr = Attr<StaticAttrOpcode>;
|
237 | export type StaticComponentAttr = Attr<StaticComponentAttrOpcode>;
|
238 |
|
239 | export type AnyStaticAttr = StaticAttr | StaticComponentAttr;
|
240 |
|
241 | export type AttrSplat = [AttrSplatOpcode, YieldTo];
|
242 | export type Yield = [YieldOpcode, YieldTo, Nullable<Params>];
|
243 | export type DynamicArg = [DynamicArgOpcode, string, Expression];
|
244 | export type StaticArg = [StaticArgOpcode, string, Expression];
|
245 |
|
246 | export type DynamicAttr = Attr<DynamicAttrOpcode>;
|
247 | export type ComponentAttr = Attr<ComponentAttrOpcode>;
|
248 | export type TrustingDynamicAttr = Attr<TrustingDynamicAttrOpcode>;
|
249 | export type TrustingComponentAttr = Attr<TrustingComponentAttrOpcode>;
|
250 |
|
251 | export type AnyDynamicAttr =
|
252 | | DynamicAttr
|
253 | | ComponentAttr
|
254 | | TrustingDynamicAttr
|
255 | | TrustingComponentAttr;
|
256 |
|
257 | export type Debugger = [DebuggerOpcode, Core.DebugInfo];
|
258 | export type InElement = [
|
259 | op: InElementOpcode,
|
260 | block: SerializedInlineBlock,
|
261 | guid: string,
|
262 | destination: Expression,
|
263 | insertBefore?: Expression,
|
264 | ];
|
265 |
|
266 | export type If = [
|
267 | op: IfOpcode,
|
268 | condition: Expression,
|
269 | block: SerializedInlineBlock,
|
270 | inverse: Nullable<SerializedInlineBlock>,
|
271 | ];
|
272 |
|
273 | export type Each = [
|
274 | op: EachOpcode,
|
275 | condition: Expression,
|
276 | key: Nullable<Expression>,
|
277 | block: SerializedInlineBlock,
|
278 | inverse: Nullable<SerializedInlineBlock>,
|
279 | ];
|
280 |
|
281 | export type Let = [op: LetOpcode, positional: Core.Params, block: SerializedInlineBlock];
|
282 |
|
283 | export type WithDynamicVars = [
|
284 | op: WithDynamicVarsOpcode,
|
285 | args: Core.Hash,
|
286 | block: SerializedInlineBlock,
|
287 | ];
|
288 |
|
289 | export type InvokeComponent = [
|
290 | op: InvokeComponentOpcode,
|
291 | definition: Expression,
|
292 | positional: Core.Params,
|
293 | named: Core.Hash,
|
294 | blocks: Blocks | null,
|
295 | ];
|
296 |
|
297 | |
298 |
|
299 |
|
300 | export type Statement =
|
301 | | Append
|
302 | | TrustingAppend
|
303 | | Comment
|
304 | | Modifier
|
305 | | Block
|
306 | | Component
|
307 | | OpenElement
|
308 | | OpenElementWithSplat
|
309 | | FlushElement
|
310 | | CloseElement
|
311 | | Attribute
|
312 | | AttrSplat
|
313 | | Yield
|
314 | | StaticArg
|
315 | | DynamicArg
|
316 | | Debugger
|
317 | | InElement
|
318 | | If
|
319 | | Each
|
320 | | Let
|
321 | | WithDynamicVars
|
322 | | InvokeComponent;
|
323 |
|
324 | export type Attribute =
|
325 | | StaticAttr
|
326 | | StaticComponentAttr
|
327 | | DynamicAttr
|
328 | | TrustingDynamicAttr
|
329 | | ComponentAttr
|
330 | | TrustingComponentAttr;
|
331 |
|
332 | export type ComponentFeature = Modifier | AttrSplat;
|
333 | export type Argument = StaticArg | DynamicArg;
|
334 |
|
335 | export type ElementParameter = Attribute | Argument | ComponentFeature;
|
336 | }
|
337 |
|
338 |
|
339 | export type Statement = Statements.Statement;
|
340 | export type Attribute = Statements.Attribute;
|
341 | export type Argument = Statements.Argument;
|
342 | export type ElementParameter = Statements.ElementParameter;
|
343 |
|
344 | export type SexpSyntax = Statement | TupleExpression;
|
345 |
|
346 | export type Syntax = SexpSyntax | Expressions.Value | undefined;
|
347 |
|
348 | export type SyntaxWithInternal =
|
349 | | Syntax
|
350 | | CoreSyntax
|
351 | | SerializedTemplateBlock
|
352 | | Core.CallArgs
|
353 | | Core.NamedBlock
|
354 | | Core.ElementParameters;
|
355 |
|
356 |
|
357 |
|
358 |
|
359 | export type SerializedBlock = [statements: Statements.Statement[]];
|
360 |
|
361 | export type SerializedInlineBlock = [statements: Statements.Statement[], parameters: number[]];
|
362 |
|
363 |
|
364 |
|
365 |
|
366 | export type SerializedTemplateBlock = [
|
367 |
|
368 | Statements.Statement[],
|
369 |
|
370 | string[],
|
371 |
|
372 | boolean,
|
373 |
|
374 | string[],
|
375 | ];
|
376 |
|
377 |
|
378 |
|
379 |
|
380 | export interface SerializedTemplate {
|
381 | block: SerializedTemplateBlock;
|
382 | id?: Nullable<string>;
|
383 | moduleName: string;
|
384 | }
|
385 |
|
386 |
|
387 |
|
388 |
|
389 | export type SerializedTemplateBlockJSON = string;
|
390 |
|
391 |
|
392 |
|
393 |
|
394 | export interface SerializedTemplateWithLazyBlock {
|
395 | id?: Nullable<string>;
|
396 | block: SerializedTemplateBlockJSON;
|
397 | moduleName: string;
|
398 | scope?: (() => unknown[]) | undefined | null;
|
399 | isStrictMode: boolean;
|
400 | }
|
401 |
|
402 | /**
|
403 | * A string of Javascript containing a SerializedTemplateWithLazyBlock to be
|
404 | * concatenated into a Javascript module.
|
405 | */
|
406 | export type TemplateJavascript = string;
|
407 |
|
\ | No newline at end of file |