@constela/compiler 0.8.0 → 0.9.1
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/README.md +13 -0
- package/dist/index.d.ts +29 -4
- package/dist/index.js +29 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -45,6 +45,12 @@ The compiler transforms JSON programs through three passes:
|
|
|
45
45
|
2. **Analyze** - Semantic analysis (state, actions, components, routes)
|
|
46
46
|
3. **Transform** - AST to optimized runtime program
|
|
47
47
|
|
|
48
|
+
## Supported Features
|
|
49
|
+
|
|
50
|
+
- **setPath** - Compiles to efficient path-based state updates
|
|
51
|
+
- **Key-based each** - Compiles key expressions for list diffing
|
|
52
|
+
- **WebSocket connections** - Compiles connection definitions and send/close actions
|
|
53
|
+
|
|
48
54
|
## CompiledProgram Structure
|
|
49
55
|
|
|
50
56
|
```json
|
|
@@ -63,6 +69,13 @@ The compiler transforms JSON programs through three passes:
|
|
|
63
69
|
"state": {
|
|
64
70
|
"count": { "type": "number", "initial": 0 }
|
|
65
71
|
},
|
|
72
|
+
"connections": {
|
|
73
|
+
"chat": {
|
|
74
|
+
"type": "websocket",
|
|
75
|
+
"url": { ... },
|
|
76
|
+
"onMessage": { "action": "handleMessage" }
|
|
77
|
+
}
|
|
78
|
+
},
|
|
66
79
|
"actions": {
|
|
67
80
|
"increment": {
|
|
68
81
|
"name": "increment",
|
package/dist/index.d.ts
CHANGED
|
@@ -89,7 +89,7 @@ interface CompiledAction {
|
|
|
89
89
|
name: string;
|
|
90
90
|
steps: CompiledActionStep[];
|
|
91
91
|
}
|
|
92
|
-
type CompiledActionStep = CompiledSetStep | CompiledUpdateStep | CompiledFetchStep | CompiledStorageStep | CompiledClipboardStep | CompiledNavigateStep | CompiledImportStep | CompiledCallStep | CompiledSubscribeStep | CompiledDisposeStep | CompiledDomStep | CompiledIfStep;
|
|
92
|
+
type CompiledActionStep = CompiledSetStep | CompiledUpdateStep | CompiledSetPathStep | CompiledFetchStep | CompiledStorageStep | CompiledClipboardStep | CompiledNavigateStep | CompiledImportStep | CompiledCallStep | CompiledSubscribeStep | CompiledDisposeStep | CompiledDomStep | CompiledIfStep | CompiledSendStep | CompiledCloseStep;
|
|
93
93
|
interface CompiledSetStep {
|
|
94
94
|
do: 'set';
|
|
95
95
|
target: string;
|
|
@@ -103,6 +103,12 @@ interface CompiledUpdateStep {
|
|
|
103
103
|
index?: CompiledExpression;
|
|
104
104
|
deleteCount?: CompiledExpression;
|
|
105
105
|
}
|
|
106
|
+
interface CompiledSetPathStep {
|
|
107
|
+
do: 'setPath';
|
|
108
|
+
target: string;
|
|
109
|
+
path: CompiledExpression;
|
|
110
|
+
value: CompiledExpression;
|
|
111
|
+
}
|
|
106
112
|
interface CompiledFetchStep {
|
|
107
113
|
do: 'fetch';
|
|
108
114
|
url: CompiledExpression;
|
|
@@ -196,6 +202,21 @@ interface CompiledIfStep {
|
|
|
196
202
|
then: CompiledActionStep[];
|
|
197
203
|
else?: CompiledActionStep[];
|
|
198
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Compiled send step - sends data through a named WebSocket connection
|
|
207
|
+
*/
|
|
208
|
+
interface CompiledSendStep {
|
|
209
|
+
do: 'send';
|
|
210
|
+
connection: string;
|
|
211
|
+
data: CompiledExpression;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Compiled close step - closes a named WebSocket connection
|
|
215
|
+
*/
|
|
216
|
+
interface CompiledCloseStep {
|
|
217
|
+
do: 'close';
|
|
218
|
+
connection: string;
|
|
219
|
+
}
|
|
199
220
|
type CompiledNode = CompiledElementNode | CompiledTextNode | CompiledIfNode | CompiledEachNode | CompiledMarkdownNode | CompiledCodeNode | CompiledSlotNode;
|
|
200
221
|
interface CompiledElementNode {
|
|
201
222
|
kind: 'element';
|
|
@@ -235,7 +256,7 @@ interface CompiledSlotNode {
|
|
|
235
256
|
kind: 'slot';
|
|
236
257
|
name?: string;
|
|
237
258
|
}
|
|
238
|
-
type CompiledExpression = CompiledLitExpr | CompiledStateExpr | CompiledVarExpr | CompiledBinExpr | CompiledNotExpr | CompiledCondExpr | CompiledGetExpr | CompiledRouteExpr | CompiledImportExpr | CompiledDataExpr | CompiledRefExpr | CompiledIndexExpr | CompiledParamExpr | CompiledStyleExpr;
|
|
259
|
+
type CompiledExpression = CompiledLitExpr | CompiledStateExpr | CompiledVarExpr | CompiledBinExpr | CompiledNotExpr | CompiledCondExpr | CompiledGetExpr | CompiledRouteExpr | CompiledImportExpr | CompiledDataExpr | CompiledRefExpr | CompiledIndexExpr | CompiledParamExpr | CompiledStyleExpr | CompiledConcatExpr;
|
|
239
260
|
interface CompiledLitExpr {
|
|
240
261
|
expr: 'lit';
|
|
241
262
|
value: string | number | boolean | null | unknown[];
|
|
@@ -301,10 +322,14 @@ interface CompiledStyleExpr {
|
|
|
301
322
|
name: string;
|
|
302
323
|
variants?: Record<string, CompiledExpression>;
|
|
303
324
|
}
|
|
325
|
+
interface CompiledConcatExpr {
|
|
326
|
+
expr: 'concat';
|
|
327
|
+
items: CompiledExpression[];
|
|
328
|
+
}
|
|
304
329
|
interface CompiledEventHandler {
|
|
305
330
|
event: string;
|
|
306
331
|
action: string;
|
|
307
|
-
payload?: CompiledExpression
|
|
332
|
+
payload?: CompiledExpression | Record<string, CompiledExpression>;
|
|
308
333
|
}
|
|
309
334
|
/**
|
|
310
335
|
* Transforms the validated and analyzed AST into a CompiledProgram
|
|
@@ -434,4 +459,4 @@ declare function transformLayoutPass(layout: LayoutProgram, _context: LayoutAnal
|
|
|
434
459
|
*/
|
|
435
460
|
declare function composeLayoutWithPage(layout: CompiledProgram, page: CompiledProgram, layoutParams?: Record<string, Expression>, slots?: Record<string, ViewNode>): CompiledProgram;
|
|
436
461
|
|
|
437
|
-
export { type AnalysisContext, type AnalyzePassFailure, type AnalyzePassResult, type AnalyzePassSuccess, type CompileFailure, type CompileResult, type CompileSuccess, type CompiledAction, type CompiledActionStep, type CompiledBinExpr, type CompiledCallStep, type CompiledClipboardStep, type CompiledCodeNode, type CompiledCondExpr, type CompiledDataExpr, type CompiledDisposeStep, type CompiledDomStep, type CompiledEachNode, type CompiledElementNode, type CompiledEventHandler, type CompiledExpression, type CompiledFetchStep, type CompiledGetExpr, type CompiledIfNode, type CompiledIfStep, type CompiledImportExpr, type CompiledImportStep, type CompiledIndexExpr, type CompiledLayoutProgram, type CompiledLifecycleHooks, type CompiledLitExpr, type CompiledMarkdownNode, type CompiledNavigateStep, type CompiledNode, type CompiledNotExpr, type CompiledProgram, type CompiledRefExpr, type CompiledRouteDefinition, type CompiledRouteExpr, type CompiledSetStep, type CompiledSlotNode, type CompiledStateExpr, type CompiledStorageStep, type CompiledSubscribeStep, type CompiledTextNode, type CompiledUpdateStep, type CompiledVarExpr, type LayoutAnalysisContext, type LayoutAnalysisFailure, type LayoutAnalysisResult, type LayoutAnalysisSuccess, type ValidatePassFailure, type ValidatePassResult, type ValidatePassSuccess, analyzeLayoutPass, analyzePass, compile, composeLayoutWithPage, transformLayoutPass, transformPass, validatePass };
|
|
462
|
+
export { type AnalysisContext, type AnalyzePassFailure, type AnalyzePassResult, type AnalyzePassSuccess, type CompileFailure, type CompileResult, type CompileSuccess, type CompiledAction, type CompiledActionStep, type CompiledBinExpr, type CompiledCallStep, type CompiledClipboardStep, type CompiledCloseStep, type CompiledCodeNode, type CompiledConcatExpr, type CompiledCondExpr, type CompiledDataExpr, type CompiledDisposeStep, type CompiledDomStep, type CompiledEachNode, type CompiledElementNode, type CompiledEventHandler, type CompiledExpression, type CompiledFetchStep, type CompiledGetExpr, type CompiledIfNode, type CompiledIfStep, type CompiledImportExpr, type CompiledImportStep, type CompiledIndexExpr, type CompiledLayoutProgram, type CompiledLifecycleHooks, type CompiledLitExpr, type CompiledMarkdownNode, type CompiledNavigateStep, type CompiledNode, type CompiledNotExpr, type CompiledParamExpr, type CompiledProgram, type CompiledRefExpr, type CompiledRouteDefinition, type CompiledRouteExpr, type CompiledSendStep, type CompiledSetPathStep, type CompiledSetStep, type CompiledSlotNode, type CompiledStateExpr, type CompiledStorageStep, type CompiledStyleExpr, type CompiledSubscribeStep, type CompiledTextNode, type CompiledUpdateStep, type CompiledVarExpr, type LayoutAnalysisContext, type LayoutAnalysisFailure, type LayoutAnalysisResult, type LayoutAnalysisSuccess, type ValidatePassFailure, type ValidatePassResult, type ValidatePassSuccess, analyzeLayoutPass, analyzePass, compile, composeLayoutWithPage, transformLayoutPass, transformPass, validatePass };
|
package/dist/index.js
CHANGED
|
@@ -1178,6 +1178,11 @@ function transformExpression(expr, ctx) {
|
|
|
1178
1178
|
}
|
|
1179
1179
|
return styleExpr;
|
|
1180
1180
|
}
|
|
1181
|
+
case "concat":
|
|
1182
|
+
return {
|
|
1183
|
+
expr: "concat",
|
|
1184
|
+
items: expr.items.map((item) => transformExpression(item, ctx))
|
|
1185
|
+
};
|
|
1181
1186
|
}
|
|
1182
1187
|
}
|
|
1183
1188
|
function transformEventHandler(handler, ctx) {
|
|
@@ -1216,6 +1221,15 @@ function transformActionStep(step) {
|
|
|
1216
1221
|
}
|
|
1217
1222
|
return updateStep;
|
|
1218
1223
|
}
|
|
1224
|
+
case "setPath": {
|
|
1225
|
+
const setPathStep = step;
|
|
1226
|
+
return {
|
|
1227
|
+
do: "setPath",
|
|
1228
|
+
target: setPathStep.target,
|
|
1229
|
+
path: transformExpression(setPathStep.path, emptyContext),
|
|
1230
|
+
value: transformExpression(setPathStep.value, emptyContext)
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1219
1233
|
case "fetch": {
|
|
1220
1234
|
const fetchStep = {
|
|
1221
1235
|
do: "fetch",
|
|
@@ -1355,6 +1369,21 @@ function transformActionStep(step) {
|
|
|
1355
1369
|
...domStep.attribute && { attribute: domStep.attribute }
|
|
1356
1370
|
};
|
|
1357
1371
|
}
|
|
1372
|
+
case "send": {
|
|
1373
|
+
const sendStep = step;
|
|
1374
|
+
return {
|
|
1375
|
+
do: "send",
|
|
1376
|
+
connection: sendStep.connection,
|
|
1377
|
+
data: transformExpression(sendStep.data, emptyContext)
|
|
1378
|
+
};
|
|
1379
|
+
}
|
|
1380
|
+
case "close": {
|
|
1381
|
+
const closeStep = step;
|
|
1382
|
+
return {
|
|
1383
|
+
do: "close",
|
|
1384
|
+
connection: closeStep.connection
|
|
1385
|
+
};
|
|
1386
|
+
}
|
|
1358
1387
|
}
|
|
1359
1388
|
}
|
|
1360
1389
|
function flattenSlotChildren(children, ctx) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Compiler for Constela UI framework - AST to Program transformation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@constela/core": "0.
|
|
18
|
+
"@constela/core": "0.9.1"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^20.10.0",
|