@constela/compiler 0.12.0 → 0.14.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/README.md CHANGED
@@ -11,7 +11,7 @@ npm install @constela/compiler
11
11
  ## Usage
12
12
 
13
13
  ```bash
14
- constela compile app.json --out dist/app.compiled.json
14
+ constela compile app.constela.json --out dist/app.compiled.json
15
15
  ```
16
16
 
17
17
  ## JSON Input
@@ -52,6 +52,7 @@ The compiler transforms JSON programs through three passes:
52
52
  - **WebSocket connections** - Compiles connection definitions and send/close actions
53
53
  - **concat expression** - Compiles string concatenation expressions
54
54
  - **Object payloads** - Supports object-shaped event handler payloads with expression fields
55
+ - **call/lambda expressions** - Compiles method calls and anonymous functions for array/string/Math/Date operations
55
56
 
56
57
  ## CompiledProgram Structure
57
58
 
package/dist/index.d.ts CHANGED
@@ -328,7 +328,7 @@ interface CompiledPortalNode {
328
328
  target: 'body' | 'head' | string;
329
329
  children: CompiledNode[];
330
330
  }
331
- type CompiledExpression = CompiledLitExpr | CompiledStateExpr | CompiledVarExpr | CompiledBinExpr | CompiledNotExpr | CompiledCondExpr | CompiledGetExpr | CompiledRouteExpr | CompiledImportExpr | CompiledDataExpr | CompiledRefExpr | CompiledIndexExpr | CompiledParamExpr | CompiledStyleExpr | CompiledConcatExpr | CompiledValidityExpr;
331
+ type CompiledExpression = CompiledLitExpr | CompiledStateExpr | CompiledVarExpr | CompiledBinExpr | CompiledNotExpr | CompiledCondExpr | CompiledGetExpr | CompiledRouteExpr | CompiledImportExpr | CompiledDataExpr | CompiledRefExpr | CompiledIndexExpr | CompiledParamExpr | CompiledStyleExpr | CompiledConcatExpr | CompiledValidityExpr | CompiledCallExpr | CompiledLambdaExpr | CompiledArrayExpr;
332
332
  interface CompiledLitExpr {
333
333
  expr: 'lit';
334
334
  value: string | number | boolean | null | unknown[];
@@ -403,6 +403,22 @@ interface CompiledValidityExpr {
403
403
  ref: string;
404
404
  property?: string;
405
405
  }
406
+ interface CompiledCallExpr {
407
+ expr: 'call';
408
+ target: CompiledExpression;
409
+ method: string;
410
+ args?: CompiledExpression[];
411
+ }
412
+ interface CompiledLambdaExpr {
413
+ expr: 'lambda';
414
+ param: string;
415
+ index?: string;
416
+ body: CompiledExpression;
417
+ }
418
+ interface CompiledArrayExpr {
419
+ expr: 'array';
420
+ elements: CompiledExpression[];
421
+ }
406
422
  /**
407
423
  * Compiled event handler options for special events like intersect
408
424
  */
@@ -547,4 +563,4 @@ declare function transformLayoutPass(layout: LayoutProgram, _context: LayoutAnal
547
563
  */
548
564
  declare function composeLayoutWithPage(layout: CompiledProgram, page: CompiledProgram, layoutParams?: Record<string, Expression>, slots?: Record<string, ViewNode>): CompiledProgram;
549
565
 
550
- export { type AnalysisContext, type AnalyzePassFailure, type AnalyzePassResult, type AnalyzePassSuccess, type CompileFailure, type CompileResult, type CompileSuccess, type CompiledAction, type CompiledActionStep, type CompiledBinExpr, 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 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 };
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 };
package/dist/index.js CHANGED
@@ -235,6 +235,43 @@ function validateExpression(expr, path, context, scope, paramScope) {
235
235
  case "style":
236
236
  errors.push(...validateStyleExpression(expr, path, context, scope, paramScope));
237
237
  break;
238
+ case "index":
239
+ errors.push(...validateExpression(expr.base, buildPath(path, "base"), context, scope, paramScope));
240
+ errors.push(...validateExpression(expr.key, buildPath(path, "key"), context, scope, paramScope));
241
+ break;
242
+ case "call": {
243
+ const callExpr = expr;
244
+ errors.push(...validateExpression(callExpr.target, buildPath(path, "target"), context, scope, paramScope));
245
+ if (callExpr.args) {
246
+ for (let i = 0; i < callExpr.args.length; i++) {
247
+ const arg = callExpr.args[i];
248
+ if (arg) {
249
+ errors.push(...validateExpression(arg, buildPath(path, "args", i), context, scope, paramScope));
250
+ }
251
+ }
252
+ }
253
+ break;
254
+ }
255
+ case "lambda": {
256
+ const lambdaExpr = expr;
257
+ const lambdaScope = new Set(scope);
258
+ lambdaScope.add(lambdaExpr.param);
259
+ if (lambdaExpr.index) {
260
+ lambdaScope.add(lambdaExpr.index);
261
+ }
262
+ errors.push(...validateExpression(lambdaExpr.body, buildPath(path, "body"), context, lambdaScope, paramScope));
263
+ break;
264
+ }
265
+ case "array": {
266
+ const arrayExpr = expr;
267
+ for (let i = 0; i < arrayExpr.elements.length; i++) {
268
+ const elem = arrayExpr.elements[i];
269
+ if (elem) {
270
+ errors.push(...validateExpression(elem, buildPath(path, "elements", i), context, scope, paramScope));
271
+ }
272
+ }
273
+ break;
274
+ }
238
275
  }
239
276
  return errors;
240
277
  }
@@ -571,6 +608,38 @@ function validateExpressionStateOnly(expr, path, context) {
571
608
  case "style":
572
609
  errors.push(...validateStyleExpressionStateOnly(expr, path, context));
573
610
  break;
611
+ case "index":
612
+ errors.push(...validateExpressionStateOnly(expr.base, buildPath(path, "base"), context));
613
+ errors.push(...validateExpressionStateOnly(expr.key, buildPath(path, "key"), context));
614
+ break;
615
+ case "call": {
616
+ const callExpr = expr;
617
+ errors.push(...validateExpressionStateOnly(callExpr.target, buildPath(path, "target"), context));
618
+ if (callExpr.args) {
619
+ for (let i = 0; i < callExpr.args.length; i++) {
620
+ const arg = callExpr.args[i];
621
+ if (arg) {
622
+ errors.push(...validateExpressionStateOnly(arg, buildPath(path, "args", i), context));
623
+ }
624
+ }
625
+ }
626
+ break;
627
+ }
628
+ case "lambda": {
629
+ const lambdaExpr = expr;
630
+ errors.push(...validateExpressionStateOnly(lambdaExpr.body, buildPath(path, "body"), context));
631
+ break;
632
+ }
633
+ case "array": {
634
+ const arrayExpr = expr;
635
+ for (let i = 0; i < arrayExpr.elements.length; i++) {
636
+ const elem = arrayExpr.elements[i];
637
+ if (elem) {
638
+ errors.push(...validateExpressionStateOnly(elem, buildPath(path, "elements", i), context));
639
+ }
640
+ }
641
+ break;
642
+ }
574
643
  }
575
644
  return errors;
576
645
  }
@@ -680,6 +749,43 @@ function validateExpressionInEventPayload(expr, path, context, scope) {
680
749
  case "style":
681
750
  errors.push(...validateStyleExpressionInEventPayload(expr, path, context, scope));
682
751
  break;
752
+ case "index":
753
+ errors.push(...validateExpressionInEventPayload(expr.base, buildPath(path, "base"), context, scope));
754
+ errors.push(...validateExpressionInEventPayload(expr.key, buildPath(path, "key"), context, scope));
755
+ break;
756
+ case "call": {
757
+ const callExpr = expr;
758
+ errors.push(...validateExpressionInEventPayload(callExpr.target, buildPath(path, "target"), context, scope));
759
+ if (callExpr.args) {
760
+ for (let i = 0; i < callExpr.args.length; i++) {
761
+ const arg = callExpr.args[i];
762
+ if (arg) {
763
+ errors.push(...validateExpressionInEventPayload(arg, buildPath(path, "args", i), context, scope));
764
+ }
765
+ }
766
+ }
767
+ break;
768
+ }
769
+ case "lambda": {
770
+ const lambdaExpr = expr;
771
+ const lambdaScope = new Set(scope);
772
+ lambdaScope.add(lambdaExpr.param);
773
+ if (lambdaExpr.index) {
774
+ lambdaScope.add(lambdaExpr.index);
775
+ }
776
+ errors.push(...validateExpressionInEventPayload(lambdaExpr.body, buildPath(path, "body"), context, lambdaScope));
777
+ break;
778
+ }
779
+ case "array": {
780
+ const arrayExpr = expr;
781
+ for (let i = 0; i < arrayExpr.elements.length; i++) {
782
+ const elem = arrayExpr.elements[i];
783
+ if (elem) {
784
+ errors.push(...validateExpressionInEventPayload(elem, buildPath(path, "elements", i), context, scope));
785
+ }
786
+ }
787
+ break;
788
+ }
683
789
  }
684
790
  return errors;
685
791
  }
@@ -1245,6 +1351,37 @@ function transformExpression(expr, ctx) {
1245
1351
  }
1246
1352
  return validityExpr;
1247
1353
  }
1354
+ case "call": {
1355
+ const callExpr = expr;
1356
+ const result = {
1357
+ expr: "call",
1358
+ target: transformExpression(callExpr.target, ctx),
1359
+ method: callExpr.method
1360
+ };
1361
+ if (callExpr.args && callExpr.args.length > 0) {
1362
+ result.args = callExpr.args.map((arg) => transformExpression(arg, ctx));
1363
+ }
1364
+ return result;
1365
+ }
1366
+ case "lambda": {
1367
+ const lambdaExpr = expr;
1368
+ const result = {
1369
+ expr: "lambda",
1370
+ param: lambdaExpr.param,
1371
+ body: transformExpression(lambdaExpr.body, ctx)
1372
+ };
1373
+ if (lambdaExpr.index) {
1374
+ result.index = lambdaExpr.index;
1375
+ }
1376
+ return result;
1377
+ }
1378
+ case "array": {
1379
+ const arrayExpr = expr;
1380
+ return {
1381
+ expr: "array",
1382
+ elements: arrayExpr.elements.map((elem) => transformExpression(elem, ctx))
1383
+ };
1384
+ }
1248
1385
  }
1249
1386
  }
1250
1387
  function transformEventHandler(handler, ctx) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constela/compiler",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
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.13.0"
18
+ "@constela/core": "0.15.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^20.10.0",