@constela/compiler 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +173 -5
- package/dist/index.js +1087 -12
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Program, ConstelaError } from '@constela/core';
|
|
1
|
+
import { Program, ConstelaError, LayoutProgram, ComponentDef, ViewNode } from '@constela/core';
|
|
2
2
|
export { createUndefinedVarError } from '@constela/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -16,6 +16,10 @@ interface AnalysisContext {
|
|
|
16
16
|
stateNames: Set<string>;
|
|
17
17
|
actionNames: Set<string>;
|
|
18
18
|
componentNames: Set<string>;
|
|
19
|
+
routeParams: Set<string>;
|
|
20
|
+
importNames: Set<string>;
|
|
21
|
+
dataNames: Set<string>;
|
|
22
|
+
refNames: Set<string>;
|
|
19
23
|
}
|
|
20
24
|
interface AnalyzePassSuccess {
|
|
21
25
|
ok: true;
|
|
@@ -40,6 +44,7 @@ type AnalyzePassResult = AnalyzePassSuccess | AnalyzePassFailure;
|
|
|
40
44
|
* - Validates component references and props
|
|
41
45
|
* - Detects component cycles
|
|
42
46
|
* - Validates param references in component definitions
|
|
47
|
+
* - Validates data sources and getStaticPaths
|
|
43
48
|
*
|
|
44
49
|
* @param programAst - Validated AST from validate pass
|
|
45
50
|
* @returns AnalyzePassResult
|
|
@@ -53,20 +58,36 @@ declare function analyzePass(programAst: Program): AnalyzePassResult;
|
|
|
53
58
|
* that is optimized for runtime execution.
|
|
54
59
|
*/
|
|
55
60
|
|
|
61
|
+
interface CompiledRouteDefinition {
|
|
62
|
+
path: string;
|
|
63
|
+
params: string[];
|
|
64
|
+
title?: CompiledExpression;
|
|
65
|
+
layout?: string;
|
|
66
|
+
meta?: Record<string, CompiledExpression>;
|
|
67
|
+
}
|
|
68
|
+
interface CompiledLifecycleHooks {
|
|
69
|
+
onMount?: string;
|
|
70
|
+
onUnmount?: string;
|
|
71
|
+
onRouteEnter?: string;
|
|
72
|
+
onRouteLeave?: string;
|
|
73
|
+
}
|
|
56
74
|
interface CompiledProgram {
|
|
57
75
|
version: '1.0';
|
|
76
|
+
route?: CompiledRouteDefinition;
|
|
77
|
+
lifecycle?: CompiledLifecycleHooks;
|
|
58
78
|
state: Record<string, {
|
|
59
79
|
type: string;
|
|
60
80
|
initial: unknown;
|
|
61
81
|
}>;
|
|
62
82
|
actions: Record<string, CompiledAction>;
|
|
63
83
|
view: CompiledNode;
|
|
84
|
+
importData?: Record<string, unknown>;
|
|
64
85
|
}
|
|
65
86
|
interface CompiledAction {
|
|
66
87
|
name: string;
|
|
67
88
|
steps: CompiledActionStep[];
|
|
68
89
|
}
|
|
69
|
-
type CompiledActionStep = CompiledSetStep | CompiledUpdateStep | CompiledFetchStep;
|
|
90
|
+
type CompiledActionStep = CompiledSetStep | CompiledUpdateStep | CompiledFetchStep | CompiledStorageStep | CompiledClipboardStep | CompiledNavigateStep | CompiledImportStep | CompiledCallStep | CompiledSubscribeStep | CompiledDisposeStep;
|
|
70
91
|
interface CompiledSetStep {
|
|
71
92
|
do: 'set';
|
|
72
93
|
target: string;
|
|
@@ -89,10 +110,79 @@ interface CompiledFetchStep {
|
|
|
89
110
|
onSuccess?: CompiledActionStep[];
|
|
90
111
|
onError?: CompiledActionStep[];
|
|
91
112
|
}
|
|
113
|
+
interface CompiledStorageStep {
|
|
114
|
+
do: 'storage';
|
|
115
|
+
operation: 'get' | 'set' | 'remove';
|
|
116
|
+
key: CompiledExpression;
|
|
117
|
+
value?: CompiledExpression;
|
|
118
|
+
storage: 'local' | 'session';
|
|
119
|
+
result?: string;
|
|
120
|
+
onSuccess?: CompiledActionStep[];
|
|
121
|
+
onError?: CompiledActionStep[];
|
|
122
|
+
}
|
|
123
|
+
interface CompiledClipboardStep {
|
|
124
|
+
do: 'clipboard';
|
|
125
|
+
operation: 'write' | 'read';
|
|
126
|
+
value?: CompiledExpression;
|
|
127
|
+
result?: string;
|
|
128
|
+
onSuccess?: CompiledActionStep[];
|
|
129
|
+
onError?: CompiledActionStep[];
|
|
130
|
+
}
|
|
131
|
+
interface CompiledNavigateStep {
|
|
132
|
+
do: 'navigate';
|
|
133
|
+
url: CompiledExpression;
|
|
134
|
+
target?: '_self' | '_blank';
|
|
135
|
+
replace?: boolean;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Compiled ref expression
|
|
139
|
+
*/
|
|
140
|
+
interface CompiledRefExpr {
|
|
141
|
+
expr: 'ref';
|
|
142
|
+
name: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Compiled import step
|
|
146
|
+
*/
|
|
147
|
+
interface CompiledImportStep {
|
|
148
|
+
do: 'import';
|
|
149
|
+
module: string;
|
|
150
|
+
result: string;
|
|
151
|
+
onSuccess?: CompiledActionStep[];
|
|
152
|
+
onError?: CompiledActionStep[];
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Compiled call step
|
|
156
|
+
*/
|
|
157
|
+
interface CompiledCallStep {
|
|
158
|
+
do: 'call';
|
|
159
|
+
target: CompiledExpression;
|
|
160
|
+
args?: CompiledExpression[];
|
|
161
|
+
result?: string;
|
|
162
|
+
onSuccess?: CompiledActionStep[];
|
|
163
|
+
onError?: CompiledActionStep[];
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Compiled subscribe step
|
|
167
|
+
*/
|
|
168
|
+
interface CompiledSubscribeStep {
|
|
169
|
+
do: 'subscribe';
|
|
170
|
+
target: CompiledExpression;
|
|
171
|
+
event: string;
|
|
172
|
+
action: string;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Compiled dispose step
|
|
176
|
+
*/
|
|
177
|
+
interface CompiledDisposeStep {
|
|
178
|
+
do: 'dispose';
|
|
179
|
+
target: CompiledExpression;
|
|
180
|
+
}
|
|
92
181
|
type CompiledNode = CompiledElementNode | CompiledTextNode | CompiledIfNode | CompiledEachNode | CompiledMarkdownNode | CompiledCodeNode;
|
|
93
182
|
interface CompiledElementNode {
|
|
94
183
|
kind: 'element';
|
|
95
184
|
tag: string;
|
|
185
|
+
ref?: string;
|
|
96
186
|
props?: Record<string, CompiledExpression | CompiledEventHandler>;
|
|
97
187
|
children?: CompiledNode[];
|
|
98
188
|
}
|
|
@@ -123,7 +213,7 @@ interface CompiledCodeNode {
|
|
|
123
213
|
language: CompiledExpression;
|
|
124
214
|
content: CompiledExpression;
|
|
125
215
|
}
|
|
126
|
-
type CompiledExpression = CompiledLitExpr | CompiledStateExpr | CompiledVarExpr | CompiledBinExpr | CompiledNotExpr | CompiledCondExpr | CompiledGetExpr;
|
|
216
|
+
type CompiledExpression = CompiledLitExpr | CompiledStateExpr | CompiledVarExpr | CompiledBinExpr | CompiledNotExpr | CompiledCondExpr | CompiledGetExpr | CompiledRouteExpr | CompiledImportExpr | CompiledRefExpr;
|
|
127
217
|
interface CompiledLitExpr {
|
|
128
218
|
expr: 'lit';
|
|
129
219
|
value: string | number | boolean | null | unknown[];
|
|
@@ -158,6 +248,16 @@ interface CompiledGetExpr {
|
|
|
158
248
|
base: CompiledExpression;
|
|
159
249
|
path: string;
|
|
160
250
|
}
|
|
251
|
+
interface CompiledRouteExpr {
|
|
252
|
+
expr: 'route';
|
|
253
|
+
name: string;
|
|
254
|
+
source: 'param' | 'query' | 'path';
|
|
255
|
+
}
|
|
256
|
+
interface CompiledImportExpr {
|
|
257
|
+
expr: 'import';
|
|
258
|
+
name: string;
|
|
259
|
+
path?: string;
|
|
260
|
+
}
|
|
161
261
|
interface CompiledEventHandler {
|
|
162
262
|
event: string;
|
|
163
263
|
action: string;
|
|
@@ -168,9 +268,10 @@ interface CompiledEventHandler {
|
|
|
168
268
|
*
|
|
169
269
|
* @param ast - Validated AST from validate pass
|
|
170
270
|
* @param _context - Analysis context from analyze pass (unused in current implementation)
|
|
271
|
+
* @param importData - Optional resolved import data to include in the compiled program
|
|
171
272
|
* @returns CompiledProgram
|
|
172
273
|
*/
|
|
173
|
-
declare function transformPass(ast: Program, _context: AnalysisContext): CompiledProgram;
|
|
274
|
+
declare function transformPass(ast: Program, _context: AnalysisContext, importData?: Record<string, unknown>): CompiledProgram;
|
|
174
275
|
|
|
175
276
|
/**
|
|
176
277
|
* Main compile function for @constela/compiler
|
|
@@ -222,4 +323,71 @@ type ValidatePassResult = ValidatePassSuccess | ValidatePassFailure;
|
|
|
222
323
|
*/
|
|
223
324
|
declare function validatePass(input: unknown): ValidatePassResult;
|
|
224
325
|
|
|
225
|
-
|
|
326
|
+
/**
|
|
327
|
+
* Layout Analysis Pass - Semantic validation for layout programs
|
|
328
|
+
*
|
|
329
|
+
* This pass performs semantic analysis on layout programs:
|
|
330
|
+
* - Validates that at least one slot node exists
|
|
331
|
+
* - Detects duplicate named slots
|
|
332
|
+
* - Validates state and action references within layouts
|
|
333
|
+
* - Warns/errors for slots inside loops
|
|
334
|
+
*/
|
|
335
|
+
|
|
336
|
+
interface LayoutAnalysisContext {
|
|
337
|
+
stateNames: Set<string>;
|
|
338
|
+
actionNames: Set<string>;
|
|
339
|
+
componentNames: Set<string>;
|
|
340
|
+
routeParams: Set<string>;
|
|
341
|
+
importNames: Set<string>;
|
|
342
|
+
slotNames: Set<string>;
|
|
343
|
+
hasDefaultSlot: boolean;
|
|
344
|
+
}
|
|
345
|
+
interface LayoutAnalysisSuccess {
|
|
346
|
+
ok: true;
|
|
347
|
+
context: LayoutAnalysisContext;
|
|
348
|
+
}
|
|
349
|
+
interface LayoutAnalysisFailure {
|
|
350
|
+
ok: false;
|
|
351
|
+
errors: ConstelaError[];
|
|
352
|
+
}
|
|
353
|
+
type LayoutAnalysisResult = LayoutAnalysisSuccess | LayoutAnalysisFailure;
|
|
354
|
+
/**
|
|
355
|
+
* Performs static analysis on a layout program
|
|
356
|
+
*
|
|
357
|
+
* - Validates at least one slot exists
|
|
358
|
+
* - Detects duplicate slot names
|
|
359
|
+
* - Validates state references
|
|
360
|
+
* - Validates action references
|
|
361
|
+
*
|
|
362
|
+
* @param layout - Layout program to analyze
|
|
363
|
+
* @returns LayoutAnalysisResult
|
|
364
|
+
*/
|
|
365
|
+
declare function analyzeLayoutPass(layout: LayoutProgram): LayoutAnalysisResult;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Layout Transform Pass - Layout to CompiledProgram transformation and composition
|
|
369
|
+
*
|
|
370
|
+
* This pass transforms layout programs and composes them with page programs.
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
interface CompiledLayoutProgram {
|
|
374
|
+
version: '1.0';
|
|
375
|
+
type: 'layout';
|
|
376
|
+
state: Record<string, {
|
|
377
|
+
type: string;
|
|
378
|
+
initial: unknown;
|
|
379
|
+
}>;
|
|
380
|
+
actions: CompiledAction[];
|
|
381
|
+
view: CompiledNode;
|
|
382
|
+
components?: Record<string, ComponentDef> | undefined;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Transforms a layout program into a compiled layout
|
|
386
|
+
*/
|
|
387
|
+
declare function transformLayoutPass(layout: LayoutProgram, _context: LayoutAnalysisContext): CompiledLayoutProgram;
|
|
388
|
+
/**
|
|
389
|
+
* Composes a layout with a page, inserting page content into slots
|
|
390
|
+
*/
|
|
391
|
+
declare function composeLayoutWithPage(layout: CompiledProgram, page: CompiledProgram, slots?: Record<string, ViewNode>): CompiledProgram;
|
|
392
|
+
|
|
393
|
+
export { type AnalysisContext, type AnalyzePassFailure, type AnalyzePassResult, type AnalyzePassSuccess, type CompileFailure, type CompileResult, type CompileSuccess, type CompiledAction, type CompiledActionStep, type CompiledCallStep, type CompiledClipboardStep, type CompiledCodeNode, type CompiledDisposeStep, type CompiledEachNode, type CompiledElementNode, type CompiledEventHandler, type CompiledExpression, type CompiledFetchStep, type CompiledIfNode, type CompiledImportExpr, type CompiledImportStep, type CompiledLayoutProgram, type CompiledLifecycleHooks, type CompiledMarkdownNode, type CompiledNavigateStep, type CompiledNode, type CompiledProgram, type CompiledRefExpr, type CompiledRouteDefinition, type CompiledRouteExpr, type CompiledSetStep, type CompiledStorageStep, type CompiledSubscribeStep, type CompiledTextNode, type CompiledUpdateStep, type LayoutAnalysisContext, type LayoutAnalysisFailure, type LayoutAnalysisResult, type LayoutAnalysisSuccess, type ValidatePassFailure, type ValidatePassResult, type ValidatePassSuccess, analyzeLayoutPass, analyzePass, compile, composeLayoutWithPage, transformLayoutPass, transformPass, validatePass };
|