@constela/compiler 0.14.3 → 0.14.5
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 +31 -0
- package/dist/index.d.ts +15 -2
- package/dist/index.js +161 -50
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -54,6 +54,37 @@ The compiler transforms JSON programs through three passes:
|
|
|
54
54
|
- **Object payloads** - Supports object-shaped event handler payloads with expression fields
|
|
55
55
|
- **call/lambda expressions** - Compiles method calls and anonymous functions for array/string/Math/Date operations
|
|
56
56
|
- **array expression** - Compiles dynamic array construction from expressions
|
|
57
|
+
- **localState/localActions** - Component-scoped state with instance isolation
|
|
58
|
+
|
|
59
|
+
## Component Local State
|
|
60
|
+
|
|
61
|
+
Components can define `localState` and `localActions` for instance-scoped state:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"components": {
|
|
66
|
+
"Accordion": {
|
|
67
|
+
"params": { "title": { "type": "string" } },
|
|
68
|
+
"localState": {
|
|
69
|
+
"isExpanded": { "type": "boolean", "initial": false }
|
|
70
|
+
},
|
|
71
|
+
"localActions": [
|
|
72
|
+
{
|
|
73
|
+
"name": "toggle",
|
|
74
|
+
"steps": [{ "do": "update", "target": "isExpanded", "operation": "toggle" }]
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
"view": { ... }
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The compiler:
|
|
84
|
+
1. Validates local state types and initial values
|
|
85
|
+
2. Wraps component views with `localState` nodes
|
|
86
|
+
3. Transforms local actions with instance-scoped store references
|
|
87
|
+
4. Handles param substitution within component views
|
|
57
88
|
|
|
58
89
|
## CompiledProgram Structure
|
|
59
90
|
|
package/dist/index.d.ts
CHANGED
|
@@ -102,7 +102,7 @@ interface CompiledAction {
|
|
|
102
102
|
name: string;
|
|
103
103
|
steps: CompiledActionStep[];
|
|
104
104
|
}
|
|
105
|
-
type CompiledActionStep = CompiledSetStep | CompiledUpdateStep | CompiledSetPathStep | CompiledFetchStep | CompiledStorageStep | CompiledClipboardStep | CompiledNavigateStep | CompiledImportStep | CompiledCallStep | CompiledSubscribeStep | CompiledDisposeStep | CompiledDomStep | CompiledIfStep | CompiledSendStep | CompiledCloseStep | CompiledDelayStep | CompiledIntervalStep | CompiledClearTimerStep | CompiledFocusStep;
|
|
105
|
+
type CompiledActionStep = CompiledSetStep | CompiledUpdateStep | CompiledSetPathStep | CompiledFetchStep | CompiledStorageStep | CompiledClipboardStep | CompiledNavigateStep | CompiledImportStep | CompiledCallStep | CompiledSubscribeStep | CompiledDisposeStep | CompiledDomStep | CompiledIfStep | CompiledSendStep | CompiledCloseStep | CompiledDelayStep | CompiledIntervalStep | CompiledClearTimerStep | CompiledFocusStep | CompiledGenerateStep;
|
|
106
106
|
interface CompiledSetStep {
|
|
107
107
|
do: 'set';
|
|
108
108
|
target: string;
|
|
@@ -265,6 +265,19 @@ interface CompiledFocusStep {
|
|
|
265
265
|
onSuccess?: CompiledActionStep[];
|
|
266
266
|
onError?: CompiledActionStep[];
|
|
267
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Compiled generate step for AI generation
|
|
270
|
+
*/
|
|
271
|
+
interface CompiledGenerateStep {
|
|
272
|
+
do: 'generate';
|
|
273
|
+
provider: 'anthropic' | 'openai';
|
|
274
|
+
prompt: CompiledExpression;
|
|
275
|
+
output: 'component' | 'view';
|
|
276
|
+
result: string;
|
|
277
|
+
model?: string;
|
|
278
|
+
onSuccess?: CompiledActionStep[];
|
|
279
|
+
onError?: CompiledActionStep[];
|
|
280
|
+
}
|
|
268
281
|
/**
|
|
269
282
|
* Compiled local action
|
|
270
283
|
*/
|
|
@@ -563,4 +576,4 @@ declare function transformLayoutPass(layout: LayoutProgram, _context: LayoutAnal
|
|
|
563
576
|
*/
|
|
564
577
|
declare function composeLayoutWithPage(layout: CompiledProgram, page: CompiledProgram, layoutParams?: Record<string, Expression>, slots?: Record<string, ViewNode>): CompiledProgram;
|
|
565
578
|
|
|
566
|
-
export { type AnalysisContext, type AnalyzePassFailure, type AnalyzePassResult, type AnalyzePassSuccess, type CompileFailure, type CompileResult, type CompileSuccess, type CompiledAction, type CompiledActionStep, type CompiledArrayExpr, type CompiledBinExpr, type CompiledCallExpr, type CompiledCallStep, type CompiledClearTimerStep, type CompiledClipboardStep, type CompiledCloseStep, type CompiledCodeNode, type CompiledConcatExpr, type CompiledCondExpr, type CompiledDataExpr, type CompiledDelayStep, type CompiledDisposeStep, type CompiledDomStep, type CompiledEachNode, type CompiledElementNode, type CompiledEventHandler, type CompiledEventHandlerOptions, type CompiledExpression, type CompiledFetchStep, type CompiledFocusStep, type CompiledGetExpr, type CompiledIfNode, type CompiledIfStep, type CompiledImportExpr, type CompiledImportStep, type CompiledIndexExpr, type CompiledIntervalStep, type CompiledLambdaExpr, type CompiledLayoutProgram, type CompiledLifecycleHooks, type CompiledLitExpr, type CompiledLocalAction, type CompiledLocalStateNode, type CompiledMarkdownNode, type CompiledNavigateStep, type CompiledNode, type CompiledNotExpr, type CompiledParamExpr, type CompiledPortalNode, 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 CompiledValidityExpr, type CompiledVarExpr, type LayoutAnalysisContext, type LayoutAnalysisFailure, type LayoutAnalysisResult, type LayoutAnalysisSuccess, type ValidatePassFailure, type ValidatePassResult, type ValidatePassSuccess, analyzeLayoutPass, analyzePass, compile, composeLayoutWithPage, transformLayoutPass, transformPass, validatePass };
|
|
579
|
+
export { type AnalysisContext, type AnalyzePassFailure, type AnalyzePassResult, type AnalyzePassSuccess, type CompileFailure, type CompileResult, type CompileSuccess, type CompiledAction, type CompiledActionStep, type CompiledArrayExpr, type CompiledBinExpr, type CompiledCallExpr, type CompiledCallStep, type CompiledClearTimerStep, type CompiledClipboardStep, type CompiledCloseStep, type CompiledCodeNode, type CompiledConcatExpr, type CompiledCondExpr, type CompiledDataExpr, type CompiledDelayStep, type CompiledDisposeStep, type CompiledDomStep, type CompiledEachNode, type CompiledElementNode, type CompiledEventHandler, type CompiledEventHandlerOptions, type CompiledExpression, type CompiledFetchStep, type CompiledFocusStep, type CompiledGenerateStep, type CompiledGetExpr, type CompiledIfNode, type CompiledIfStep, type CompiledImportExpr, type CompiledImportStep, type CompiledIndexExpr, type CompiledIntervalStep, type CompiledLambdaExpr, type CompiledLayoutProgram, type CompiledLifecycleHooks, type CompiledLitExpr, type CompiledLocalAction, type CompiledLocalStateNode, type CompiledMarkdownNode, type CompiledNavigateStep, type CompiledNode, type CompiledNotExpr, type CompiledParamExpr, type CompiledPortalNode, 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 CompiledValidityExpr, 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
|
@@ -1667,6 +1667,26 @@ function transformActionStep(step) {
|
|
|
1667
1667
|
}
|
|
1668
1668
|
return compiledIfStep;
|
|
1669
1669
|
}
|
|
1670
|
+
case "generate": {
|
|
1671
|
+
const generateStep = step;
|
|
1672
|
+
const compiledGenerateStep = {
|
|
1673
|
+
do: "generate",
|
|
1674
|
+
provider: generateStep.provider,
|
|
1675
|
+
prompt: transformExpression(generateStep.prompt, emptyContext),
|
|
1676
|
+
output: generateStep.output,
|
|
1677
|
+
result: generateStep.result
|
|
1678
|
+
};
|
|
1679
|
+
if (generateStep.model) {
|
|
1680
|
+
compiledGenerateStep.model = generateStep.model;
|
|
1681
|
+
}
|
|
1682
|
+
if (generateStep.onSuccess) {
|
|
1683
|
+
compiledGenerateStep.onSuccess = generateStep.onSuccess.map(transformActionStep);
|
|
1684
|
+
}
|
|
1685
|
+
if (generateStep.onError) {
|
|
1686
|
+
compiledGenerateStep.onError = generateStep.onError.map(transformActionStep);
|
|
1687
|
+
}
|
|
1688
|
+
return compiledGenerateStep;
|
|
1689
|
+
}
|
|
1670
1690
|
}
|
|
1671
1691
|
}
|
|
1672
1692
|
function flattenSlotChildren(children, ctx) {
|
|
@@ -2187,12 +2207,17 @@ function transformState2(state) {
|
|
|
2187
2207
|
}
|
|
2188
2208
|
return result;
|
|
2189
2209
|
}
|
|
2190
|
-
function transformExpression2(expr) {
|
|
2210
|
+
function transformExpression2(expr, ctx) {
|
|
2191
2211
|
switch (expr.expr) {
|
|
2192
2212
|
case "lit":
|
|
2193
2213
|
return { expr: "lit", value: expr.value };
|
|
2194
|
-
case "state":
|
|
2195
|
-
|
|
2214
|
+
case "state": {
|
|
2215
|
+
const stateExpr = { expr: "state", name: expr.name };
|
|
2216
|
+
if (expr.path) {
|
|
2217
|
+
stateExpr.path = expr.path;
|
|
2218
|
+
}
|
|
2219
|
+
return stateExpr;
|
|
2220
|
+
}
|
|
2196
2221
|
case "var": {
|
|
2197
2222
|
const varExpr = { expr: "var", name: expr.name };
|
|
2198
2223
|
if (expr.path) {
|
|
@@ -2204,25 +2229,25 @@ function transformExpression2(expr) {
|
|
|
2204
2229
|
return {
|
|
2205
2230
|
expr: "bin",
|
|
2206
2231
|
op: expr.op,
|
|
2207
|
-
left: transformExpression2(expr.left),
|
|
2208
|
-
right: transformExpression2(expr.right)
|
|
2232
|
+
left: transformExpression2(expr.left, ctx),
|
|
2233
|
+
right: transformExpression2(expr.right, ctx)
|
|
2209
2234
|
};
|
|
2210
2235
|
case "not":
|
|
2211
2236
|
return {
|
|
2212
2237
|
expr: "not",
|
|
2213
|
-
operand: transformExpression2(expr.operand)
|
|
2238
|
+
operand: transformExpression2(expr.operand, ctx)
|
|
2214
2239
|
};
|
|
2215
2240
|
case "cond":
|
|
2216
2241
|
return {
|
|
2217
2242
|
expr: "cond",
|
|
2218
|
-
if: transformExpression2(expr.if),
|
|
2219
|
-
then: transformExpression2(expr.then),
|
|
2220
|
-
else: transformExpression2(expr.else)
|
|
2243
|
+
if: transformExpression2(expr.if, ctx),
|
|
2244
|
+
then: transformExpression2(expr.then, ctx),
|
|
2245
|
+
else: transformExpression2(expr.else, ctx)
|
|
2221
2246
|
};
|
|
2222
2247
|
case "get":
|
|
2223
2248
|
return {
|
|
2224
2249
|
expr: "get",
|
|
2225
|
-
base: transformExpression2(expr.base),
|
|
2250
|
+
base: transformExpression2(expr.base, ctx),
|
|
2226
2251
|
path: expr.path
|
|
2227
2252
|
};
|
|
2228
2253
|
case "route":
|
|
@@ -2246,6 +2271,60 @@ function transformExpression2(expr) {
|
|
|
2246
2271
|
return dataExpr;
|
|
2247
2272
|
}
|
|
2248
2273
|
case "param": {
|
|
2274
|
+
if (ctx?.currentParams !== void 0) {
|
|
2275
|
+
const paramValue = ctx.currentParams[expr.name];
|
|
2276
|
+
if (paramValue !== void 0) {
|
|
2277
|
+
if (expr.path) {
|
|
2278
|
+
if (paramValue.expr === "var") {
|
|
2279
|
+
const varExpr = paramValue;
|
|
2280
|
+
const existingPath = varExpr.path;
|
|
2281
|
+
const resultPath = existingPath ? `${existingPath}.${expr.path}` : expr.path;
|
|
2282
|
+
return {
|
|
2283
|
+
expr: "var",
|
|
2284
|
+
name: varExpr.name,
|
|
2285
|
+
path: resultPath
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
if (paramValue.expr === "state") {
|
|
2289
|
+
const stateExpr = paramValue;
|
|
2290
|
+
const existingPath = stateExpr.path;
|
|
2291
|
+
const resultPath = existingPath ? `${existingPath}.${expr.path}` : expr.path;
|
|
2292
|
+
return {
|
|
2293
|
+
expr: "state",
|
|
2294
|
+
name: stateExpr.name,
|
|
2295
|
+
path: resultPath
|
|
2296
|
+
};
|
|
2297
|
+
}
|
|
2298
|
+
if (paramValue.expr === "import") {
|
|
2299
|
+
const importExpr = paramValue;
|
|
2300
|
+
const existingPath = importExpr.path;
|
|
2301
|
+
const resultPath = existingPath ? `${existingPath}.${expr.path}` : expr.path;
|
|
2302
|
+
return {
|
|
2303
|
+
expr: "import",
|
|
2304
|
+
name: importExpr.name,
|
|
2305
|
+
path: resultPath
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
if (paramValue.expr === "data") {
|
|
2309
|
+
const dataExpr = paramValue;
|
|
2310
|
+
const existingPath = dataExpr.path;
|
|
2311
|
+
const resultPath = existingPath ? `${existingPath}.${expr.path}` : expr.path;
|
|
2312
|
+
return {
|
|
2313
|
+
expr: "data",
|
|
2314
|
+
name: dataExpr.name,
|
|
2315
|
+
path: resultPath
|
|
2316
|
+
};
|
|
2317
|
+
}
|
|
2318
|
+
return {
|
|
2319
|
+
expr: "get",
|
|
2320
|
+
base: paramValue,
|
|
2321
|
+
path: expr.path
|
|
2322
|
+
};
|
|
2323
|
+
}
|
|
2324
|
+
return paramValue;
|
|
2325
|
+
}
|
|
2326
|
+
return { expr: "lit", value: null };
|
|
2327
|
+
}
|
|
2249
2328
|
const paramExpr = { expr: "param", name: expr.name };
|
|
2250
2329
|
if (expr.path) {
|
|
2251
2330
|
paramExpr.path = expr.path;
|
|
@@ -2254,17 +2333,48 @@ function transformExpression2(expr) {
|
|
|
2254
2333
|
}
|
|
2255
2334
|
case "ref":
|
|
2256
2335
|
return { expr: "ref", name: expr.name };
|
|
2336
|
+
case "call": {
|
|
2337
|
+
const callExpr = expr;
|
|
2338
|
+
const result = {
|
|
2339
|
+
expr: "call",
|
|
2340
|
+
target: transformExpression2(callExpr.target, ctx),
|
|
2341
|
+
method: callExpr.method
|
|
2342
|
+
};
|
|
2343
|
+
if (callExpr.args && callExpr.args.length > 0) {
|
|
2344
|
+
result.args = callExpr.args.map((arg) => transformExpression2(arg, ctx));
|
|
2345
|
+
}
|
|
2346
|
+
return result;
|
|
2347
|
+
}
|
|
2348
|
+
case "lambda": {
|
|
2349
|
+
const lambdaExpr = expr;
|
|
2350
|
+
const result = {
|
|
2351
|
+
expr: "lambda",
|
|
2352
|
+
param: lambdaExpr.param,
|
|
2353
|
+
body: transformExpression2(lambdaExpr.body, ctx)
|
|
2354
|
+
};
|
|
2355
|
+
if (lambdaExpr.index) {
|
|
2356
|
+
result.index = lambdaExpr.index;
|
|
2357
|
+
}
|
|
2358
|
+
return result;
|
|
2359
|
+
}
|
|
2360
|
+
case "array": {
|
|
2361
|
+
const arrayExpr = expr;
|
|
2362
|
+
return {
|
|
2363
|
+
expr: "array",
|
|
2364
|
+
elements: arrayExpr.elements.map((elem) => transformExpression2(elem, ctx))
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2257
2367
|
default:
|
|
2258
2368
|
return { expr: "lit", value: null };
|
|
2259
2369
|
}
|
|
2260
2370
|
}
|
|
2261
|
-
function transformActionStep2(step) {
|
|
2371
|
+
function transformActionStep2(step, ctx) {
|
|
2262
2372
|
switch (step.do) {
|
|
2263
2373
|
case "set":
|
|
2264
2374
|
return {
|
|
2265
2375
|
do: "set",
|
|
2266
2376
|
target: step.target,
|
|
2267
|
-
value: transformExpression2(step.value)
|
|
2377
|
+
value: transformExpression2(step.value, ctx)
|
|
2268
2378
|
};
|
|
2269
2379
|
case "update": {
|
|
2270
2380
|
const updateStep = {
|
|
@@ -2273,35 +2383,35 @@ function transformActionStep2(step) {
|
|
|
2273
2383
|
operation: step.operation
|
|
2274
2384
|
};
|
|
2275
2385
|
if (step.value) {
|
|
2276
|
-
updateStep.value = transformExpression2(step.value);
|
|
2386
|
+
updateStep.value = transformExpression2(step.value, ctx);
|
|
2277
2387
|
}
|
|
2278
2388
|
if (step.index) {
|
|
2279
|
-
updateStep.index = transformExpression2(step.index);
|
|
2389
|
+
updateStep.index = transformExpression2(step.index, ctx);
|
|
2280
2390
|
}
|
|
2281
2391
|
if (step.deleteCount) {
|
|
2282
|
-
updateStep.deleteCount = transformExpression2(step.deleteCount);
|
|
2392
|
+
updateStep.deleteCount = transformExpression2(step.deleteCount, ctx);
|
|
2283
2393
|
}
|
|
2284
2394
|
return updateStep;
|
|
2285
2395
|
}
|
|
2286
2396
|
case "fetch": {
|
|
2287
2397
|
const fetchStep = {
|
|
2288
2398
|
do: "fetch",
|
|
2289
|
-
url: transformExpression2(step.url)
|
|
2399
|
+
url: transformExpression2(step.url, ctx)
|
|
2290
2400
|
};
|
|
2291
2401
|
if (step.method) {
|
|
2292
2402
|
fetchStep.method = step.method;
|
|
2293
2403
|
}
|
|
2294
2404
|
if (step.body) {
|
|
2295
|
-
fetchStep.body = transformExpression2(step.body);
|
|
2405
|
+
fetchStep.body = transformExpression2(step.body, ctx);
|
|
2296
2406
|
}
|
|
2297
2407
|
if (step.result) {
|
|
2298
2408
|
fetchStep.result = step.result;
|
|
2299
2409
|
}
|
|
2300
2410
|
if (step.onSuccess) {
|
|
2301
|
-
fetchStep.onSuccess = step.onSuccess.map(transformActionStep2);
|
|
2411
|
+
fetchStep.onSuccess = step.onSuccess.map((s) => transformActionStep2(s, ctx));
|
|
2302
2412
|
}
|
|
2303
2413
|
if (step.onError) {
|
|
2304
|
-
fetchStep.onError = step.onError.map(transformActionStep2);
|
|
2414
|
+
fetchStep.onError = step.onError.map((s) => transformActionStep2(s, ctx));
|
|
2305
2415
|
}
|
|
2306
2416
|
return fetchStep;
|
|
2307
2417
|
}
|
|
@@ -2310,20 +2420,20 @@ function transformActionStep2(step) {
|
|
|
2310
2420
|
const compiledStorageStep = {
|
|
2311
2421
|
do: "storage",
|
|
2312
2422
|
operation: storageStep.operation,
|
|
2313
|
-
key: transformExpression2(storageStep.key),
|
|
2423
|
+
key: transformExpression2(storageStep.key, ctx),
|
|
2314
2424
|
storage: storageStep.storage
|
|
2315
2425
|
};
|
|
2316
2426
|
if (storageStep.value) {
|
|
2317
|
-
compiledStorageStep.value = transformExpression2(storageStep.value);
|
|
2427
|
+
compiledStorageStep.value = transformExpression2(storageStep.value, ctx);
|
|
2318
2428
|
}
|
|
2319
2429
|
if (storageStep.result) {
|
|
2320
2430
|
compiledStorageStep.result = storageStep.result;
|
|
2321
2431
|
}
|
|
2322
2432
|
if (storageStep.onSuccess) {
|
|
2323
|
-
compiledStorageStep.onSuccess = storageStep.onSuccess.map(transformActionStep2);
|
|
2433
|
+
compiledStorageStep.onSuccess = storageStep.onSuccess.map((s) => transformActionStep2(s, ctx));
|
|
2324
2434
|
}
|
|
2325
2435
|
if (storageStep.onError) {
|
|
2326
|
-
compiledStorageStep.onError = storageStep.onError.map(transformActionStep2);
|
|
2436
|
+
compiledStorageStep.onError = storageStep.onError.map((s) => transformActionStep2(s, ctx));
|
|
2327
2437
|
}
|
|
2328
2438
|
return compiledStorageStep;
|
|
2329
2439
|
}
|
|
@@ -2334,16 +2444,16 @@ function transformActionStep2(step) {
|
|
|
2334
2444
|
operation: clipboardStep.operation
|
|
2335
2445
|
};
|
|
2336
2446
|
if (clipboardStep.value) {
|
|
2337
|
-
compiledClipboardStep.value = transformExpression2(clipboardStep.value);
|
|
2447
|
+
compiledClipboardStep.value = transformExpression2(clipboardStep.value, ctx);
|
|
2338
2448
|
}
|
|
2339
2449
|
if (clipboardStep.result) {
|
|
2340
2450
|
compiledClipboardStep.result = clipboardStep.result;
|
|
2341
2451
|
}
|
|
2342
2452
|
if (clipboardStep.onSuccess) {
|
|
2343
|
-
compiledClipboardStep.onSuccess = clipboardStep.onSuccess.map(transformActionStep2);
|
|
2453
|
+
compiledClipboardStep.onSuccess = clipboardStep.onSuccess.map((s) => transformActionStep2(s, ctx));
|
|
2344
2454
|
}
|
|
2345
2455
|
if (clipboardStep.onError) {
|
|
2346
|
-
compiledClipboardStep.onError = clipboardStep.onError.map(transformActionStep2);
|
|
2456
|
+
compiledClipboardStep.onError = clipboardStep.onError.map((s) => transformActionStep2(s, ctx));
|
|
2347
2457
|
}
|
|
2348
2458
|
return compiledClipboardStep;
|
|
2349
2459
|
}
|
|
@@ -2351,7 +2461,7 @@ function transformActionStep2(step) {
|
|
|
2351
2461
|
const navigateStep = step;
|
|
2352
2462
|
const compiledNavigateStep = {
|
|
2353
2463
|
do: "navigate",
|
|
2354
|
-
url: transformExpression2(navigateStep.url)
|
|
2464
|
+
url: transformExpression2(navigateStep.url, ctx)
|
|
2355
2465
|
};
|
|
2356
2466
|
if (navigateStep.target) {
|
|
2357
2467
|
compiledNavigateStep.target = navigateStep.target;
|
|
@@ -2369,10 +2479,10 @@ function transformActionStep2(step) {
|
|
|
2369
2479
|
result: importStep.result
|
|
2370
2480
|
};
|
|
2371
2481
|
if (importStep.onSuccess) {
|
|
2372
|
-
compiledImportStep.onSuccess = importStep.onSuccess.map(transformActionStep2);
|
|
2482
|
+
compiledImportStep.onSuccess = importStep.onSuccess.map((s) => transformActionStep2(s, ctx));
|
|
2373
2483
|
}
|
|
2374
2484
|
if (importStep.onError) {
|
|
2375
|
-
compiledImportStep.onError = importStep.onError.map(transformActionStep2);
|
|
2485
|
+
compiledImportStep.onError = importStep.onError.map((s) => transformActionStep2(s, ctx));
|
|
2376
2486
|
}
|
|
2377
2487
|
return compiledImportStep;
|
|
2378
2488
|
}
|
|
@@ -2380,19 +2490,19 @@ function transformActionStep2(step) {
|
|
|
2380
2490
|
const callStep = step;
|
|
2381
2491
|
const compiledCallStep = {
|
|
2382
2492
|
do: "call",
|
|
2383
|
-
target: transformExpression2(callStep.target)
|
|
2493
|
+
target: transformExpression2(callStep.target, ctx)
|
|
2384
2494
|
};
|
|
2385
2495
|
if (callStep.args) {
|
|
2386
|
-
compiledCallStep.args = callStep.args.map((arg) => transformExpression2(arg));
|
|
2496
|
+
compiledCallStep.args = callStep.args.map((arg) => transformExpression2(arg, ctx));
|
|
2387
2497
|
}
|
|
2388
2498
|
if (callStep.result) {
|
|
2389
2499
|
compiledCallStep.result = callStep.result;
|
|
2390
2500
|
}
|
|
2391
2501
|
if (callStep.onSuccess) {
|
|
2392
|
-
compiledCallStep.onSuccess = callStep.onSuccess.map(transformActionStep2);
|
|
2502
|
+
compiledCallStep.onSuccess = callStep.onSuccess.map((s) => transformActionStep2(s, ctx));
|
|
2393
2503
|
}
|
|
2394
2504
|
if (callStep.onError) {
|
|
2395
|
-
compiledCallStep.onError = callStep.onError.map(transformActionStep2);
|
|
2505
|
+
compiledCallStep.onError = callStep.onError.map((s) => transformActionStep2(s, ctx));
|
|
2396
2506
|
}
|
|
2397
2507
|
return compiledCallStep;
|
|
2398
2508
|
}
|
|
@@ -2400,7 +2510,7 @@ function transformActionStep2(step) {
|
|
|
2400
2510
|
const subscribeStep = step;
|
|
2401
2511
|
return {
|
|
2402
2512
|
do: "subscribe",
|
|
2403
|
-
target: transformExpression2(subscribeStep.target),
|
|
2513
|
+
target: transformExpression2(subscribeStep.target, ctx),
|
|
2404
2514
|
event: subscribeStep.event,
|
|
2405
2515
|
action: subscribeStep.action
|
|
2406
2516
|
};
|
|
@@ -2409,7 +2519,7 @@ function transformActionStep2(step) {
|
|
|
2409
2519
|
const disposeStep = step;
|
|
2410
2520
|
return {
|
|
2411
2521
|
do: "dispose",
|
|
2412
|
-
target: transformExpression2(disposeStep.target)
|
|
2522
|
+
target: transformExpression2(disposeStep.target, ctx)
|
|
2413
2523
|
};
|
|
2414
2524
|
}
|
|
2415
2525
|
case "dom": {
|
|
@@ -2417,8 +2527,8 @@ function transformActionStep2(step) {
|
|
|
2417
2527
|
return {
|
|
2418
2528
|
do: "dom",
|
|
2419
2529
|
operation: domStep.operation,
|
|
2420
|
-
selector: transformExpression2(domStep.selector),
|
|
2421
|
-
...domStep.value && { value: transformExpression2(domStep.value) },
|
|
2530
|
+
selector: transformExpression2(domStep.selector, ctx),
|
|
2531
|
+
...domStep.value && { value: transformExpression2(domStep.value, ctx) },
|
|
2422
2532
|
...domStep.attribute && { attribute: domStep.attribute }
|
|
2423
2533
|
};
|
|
2424
2534
|
}
|
|
@@ -2437,12 +2547,12 @@ function transformLocalState2(localState) {
|
|
|
2437
2547
|
}
|
|
2438
2548
|
return result;
|
|
2439
2549
|
}
|
|
2440
|
-
function transformLocalActions2(localActions) {
|
|
2550
|
+
function transformLocalActions2(localActions, ctx) {
|
|
2441
2551
|
const result = {};
|
|
2442
2552
|
for (const action of localActions) {
|
|
2443
2553
|
result[action.name] = {
|
|
2444
2554
|
name: action.name,
|
|
2445
|
-
steps: action.steps.map(transformActionStep2)
|
|
2555
|
+
steps: action.steps.map((s) => transformActionStep2(s, ctx))
|
|
2446
2556
|
};
|
|
2447
2557
|
}
|
|
2448
2558
|
return result;
|
|
@@ -2451,7 +2561,7 @@ function transformActions2(actions) {
|
|
|
2451
2561
|
if (!actions) return [];
|
|
2452
2562
|
return actions.map((action) => ({
|
|
2453
2563
|
name: action.name,
|
|
2454
|
-
steps: action.steps.map(transformActionStep2)
|
|
2564
|
+
steps: action.steps.map((s) => transformActionStep2(s))
|
|
2455
2565
|
}));
|
|
2456
2566
|
}
|
|
2457
2567
|
function transformViewNode2(node, ctx) {
|
|
@@ -2470,7 +2580,7 @@ function transformViewNode2(node, ctx) {
|
|
|
2470
2580
|
action: value.action
|
|
2471
2581
|
};
|
|
2472
2582
|
} else {
|
|
2473
|
-
result.props[key] = value;
|
|
2583
|
+
result.props[key] = transformExpression2(value, ctx);
|
|
2474
2584
|
}
|
|
2475
2585
|
}
|
|
2476
2586
|
}
|
|
@@ -2484,12 +2594,12 @@ function transformViewNode2(node, ctx) {
|
|
|
2484
2594
|
case "text":
|
|
2485
2595
|
return {
|
|
2486
2596
|
kind: "text",
|
|
2487
|
-
value: node.value
|
|
2597
|
+
value: transformExpression2(node.value, ctx)
|
|
2488
2598
|
};
|
|
2489
2599
|
case "if": {
|
|
2490
2600
|
const result = {
|
|
2491
2601
|
kind: "if",
|
|
2492
|
-
condition: node.condition,
|
|
2602
|
+
condition: transformExpression2(node.condition, ctx),
|
|
2493
2603
|
then: transformViewNode2(node.then, ctx)
|
|
2494
2604
|
};
|
|
2495
2605
|
if (node.else) {
|
|
@@ -2500,7 +2610,7 @@ function transformViewNode2(node, ctx) {
|
|
|
2500
2610
|
case "each":
|
|
2501
2611
|
return {
|
|
2502
2612
|
kind: "each",
|
|
2503
|
-
items: node.items,
|
|
2613
|
+
items: transformExpression2(node.items, ctx),
|
|
2504
2614
|
as: node.as,
|
|
2505
2615
|
body: transformViewNode2(node.body, ctx)
|
|
2506
2616
|
};
|
|
@@ -2518,7 +2628,7 @@ function transformViewNode2(node, ctx) {
|
|
|
2518
2628
|
const params = {};
|
|
2519
2629
|
if (componentNode.props) {
|
|
2520
2630
|
for (const [name, expr] of Object.entries(componentNode.props)) {
|
|
2521
|
-
params[name] = transformExpression2(expr);
|
|
2631
|
+
params[name] = transformExpression2(expr, ctx);
|
|
2522
2632
|
}
|
|
2523
2633
|
}
|
|
2524
2634
|
const children = [];
|
|
@@ -2537,7 +2647,7 @@ function transformViewNode2(node, ctx) {
|
|
|
2537
2647
|
return {
|
|
2538
2648
|
kind: "localState",
|
|
2539
2649
|
state: transformLocalState2(def.localState),
|
|
2540
|
-
actions: transformLocalActions2(def.localActions ?? []),
|
|
2650
|
+
actions: transformLocalActions2(def.localActions ?? [], newCtx),
|
|
2541
2651
|
child: expandedView
|
|
2542
2652
|
};
|
|
2543
2653
|
}
|
|
@@ -2720,22 +2830,23 @@ function processNamedSlotsOnly(node, namedContent) {
|
|
|
2720
2830
|
}
|
|
2721
2831
|
return node;
|
|
2722
2832
|
}
|
|
2723
|
-
function expandComponentNode(node, components, defaultContent, namedContent) {
|
|
2833
|
+
function expandComponentNode(node, components, defaultContent, namedContent, parentCtx) {
|
|
2724
2834
|
const componentNode = node;
|
|
2725
2835
|
const def = components[componentNode.name];
|
|
2726
2836
|
if (!def) {
|
|
2727
2837
|
return { kind: "element", tag: "div" };
|
|
2728
2838
|
}
|
|
2839
|
+
const baseCtx = parentCtx ?? { components };
|
|
2729
2840
|
const params = {};
|
|
2730
2841
|
if (componentNode.props) {
|
|
2731
2842
|
for (const [name, expr] of Object.entries(componentNode.props)) {
|
|
2732
|
-
params[name] = transformExpression2(expr);
|
|
2843
|
+
params[name] = transformExpression2(expr, baseCtx);
|
|
2733
2844
|
}
|
|
2734
2845
|
}
|
|
2735
2846
|
const children = [];
|
|
2736
2847
|
if (componentNode.children && componentNode.children.length > 0) {
|
|
2737
2848
|
for (const child of componentNode.children) {
|
|
2738
|
-
const transformedChild = transformViewNode2(child,
|
|
2849
|
+
const transformedChild = transformViewNode2(child, baseCtx);
|
|
2739
2850
|
children.push(replaceSlots(transformedChild, defaultContent, namedContent, components));
|
|
2740
2851
|
}
|
|
2741
2852
|
}
|
|
@@ -2750,7 +2861,7 @@ function expandComponentNode(node, components, defaultContent, namedContent) {
|
|
|
2750
2861
|
return {
|
|
2751
2862
|
kind: "localState",
|
|
2752
2863
|
state: transformLocalState2(def.localState),
|
|
2753
|
-
actions: transformLocalActions2(def.localActions ?? []),
|
|
2864
|
+
actions: transformLocalActions2(def.localActions ?? [], newCtx),
|
|
2754
2865
|
child: processedView
|
|
2755
2866
|
};
|
|
2756
2867
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/compiler",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.5",
|
|
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.16.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^20.10.0",
|