@constela/compiler 0.12.0 → 0.13.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 +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.js +100 -0
- package/package.json +2 -2
package/README.md
CHANGED
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;
|
|
332
332
|
interface CompiledLitExpr {
|
|
333
333
|
expr: 'lit';
|
|
334
334
|
value: string | number | boolean | null | unknown[];
|
|
@@ -403,6 +403,18 @@ 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
|
+
}
|
|
406
418
|
/**
|
|
407
419
|
* Compiled event handler options for special events like intersect
|
|
408
420
|
*/
|
|
@@ -547,4 +559,4 @@ declare function transformLayoutPass(layout: LayoutProgram, _context: LayoutAnal
|
|
|
547
559
|
*/
|
|
548
560
|
declare function composeLayoutWithPage(layout: CompiledProgram, page: CompiledProgram, layoutParams?: Record<string, Expression>, slots?: Record<string, ViewNode>): CompiledProgram;
|
|
549
561
|
|
|
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 };
|
|
562
|
+
export { type AnalysisContext, type AnalyzePassFailure, type AnalyzePassResult, type AnalyzePassSuccess, type CompileFailure, type CompileResult, type CompileSuccess, type CompiledAction, type CompiledActionStep, 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,33 @@ 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
|
+
}
|
|
238
265
|
}
|
|
239
266
|
return errors;
|
|
240
267
|
}
|
|
@@ -571,6 +598,28 @@ function validateExpressionStateOnly(expr, path, context) {
|
|
|
571
598
|
case "style":
|
|
572
599
|
errors.push(...validateStyleExpressionStateOnly(expr, path, context));
|
|
573
600
|
break;
|
|
601
|
+
case "index":
|
|
602
|
+
errors.push(...validateExpressionStateOnly(expr.base, buildPath(path, "base"), context));
|
|
603
|
+
errors.push(...validateExpressionStateOnly(expr.key, buildPath(path, "key"), context));
|
|
604
|
+
break;
|
|
605
|
+
case "call": {
|
|
606
|
+
const callExpr = expr;
|
|
607
|
+
errors.push(...validateExpressionStateOnly(callExpr.target, buildPath(path, "target"), context));
|
|
608
|
+
if (callExpr.args) {
|
|
609
|
+
for (let i = 0; i < callExpr.args.length; i++) {
|
|
610
|
+
const arg = callExpr.args[i];
|
|
611
|
+
if (arg) {
|
|
612
|
+
errors.push(...validateExpressionStateOnly(arg, buildPath(path, "args", i), context));
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
break;
|
|
617
|
+
}
|
|
618
|
+
case "lambda": {
|
|
619
|
+
const lambdaExpr = expr;
|
|
620
|
+
errors.push(...validateExpressionStateOnly(lambdaExpr.body, buildPath(path, "body"), context));
|
|
621
|
+
break;
|
|
622
|
+
}
|
|
574
623
|
}
|
|
575
624
|
return errors;
|
|
576
625
|
}
|
|
@@ -680,6 +729,33 @@ function validateExpressionInEventPayload(expr, path, context, scope) {
|
|
|
680
729
|
case "style":
|
|
681
730
|
errors.push(...validateStyleExpressionInEventPayload(expr, path, context, scope));
|
|
682
731
|
break;
|
|
732
|
+
case "index":
|
|
733
|
+
errors.push(...validateExpressionInEventPayload(expr.base, buildPath(path, "base"), context, scope));
|
|
734
|
+
errors.push(...validateExpressionInEventPayload(expr.key, buildPath(path, "key"), context, scope));
|
|
735
|
+
break;
|
|
736
|
+
case "call": {
|
|
737
|
+
const callExpr = expr;
|
|
738
|
+
errors.push(...validateExpressionInEventPayload(callExpr.target, buildPath(path, "target"), context, scope));
|
|
739
|
+
if (callExpr.args) {
|
|
740
|
+
for (let i = 0; i < callExpr.args.length; i++) {
|
|
741
|
+
const arg = callExpr.args[i];
|
|
742
|
+
if (arg) {
|
|
743
|
+
errors.push(...validateExpressionInEventPayload(arg, buildPath(path, "args", i), context, scope));
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
break;
|
|
748
|
+
}
|
|
749
|
+
case "lambda": {
|
|
750
|
+
const lambdaExpr = expr;
|
|
751
|
+
const lambdaScope = new Set(scope);
|
|
752
|
+
lambdaScope.add(lambdaExpr.param);
|
|
753
|
+
if (lambdaExpr.index) {
|
|
754
|
+
lambdaScope.add(lambdaExpr.index);
|
|
755
|
+
}
|
|
756
|
+
errors.push(...validateExpressionInEventPayload(lambdaExpr.body, buildPath(path, "body"), context, lambdaScope));
|
|
757
|
+
break;
|
|
758
|
+
}
|
|
683
759
|
}
|
|
684
760
|
return errors;
|
|
685
761
|
}
|
|
@@ -1245,6 +1321,30 @@ function transformExpression(expr, ctx) {
|
|
|
1245
1321
|
}
|
|
1246
1322
|
return validityExpr;
|
|
1247
1323
|
}
|
|
1324
|
+
case "call": {
|
|
1325
|
+
const callExpr = expr;
|
|
1326
|
+
const result = {
|
|
1327
|
+
expr: "call",
|
|
1328
|
+
target: transformExpression(callExpr.target, ctx),
|
|
1329
|
+
method: callExpr.method
|
|
1330
|
+
};
|
|
1331
|
+
if (callExpr.args && callExpr.args.length > 0) {
|
|
1332
|
+
result.args = callExpr.args.map((arg) => transformExpression(arg, ctx));
|
|
1333
|
+
}
|
|
1334
|
+
return result;
|
|
1335
|
+
}
|
|
1336
|
+
case "lambda": {
|
|
1337
|
+
const lambdaExpr = expr;
|
|
1338
|
+
const result = {
|
|
1339
|
+
expr: "lambda",
|
|
1340
|
+
param: lambdaExpr.param,
|
|
1341
|
+
body: transformExpression(lambdaExpr.body, ctx)
|
|
1342
|
+
};
|
|
1343
|
+
if (lambdaExpr.index) {
|
|
1344
|
+
result.index = lambdaExpr.index;
|
|
1345
|
+
}
|
|
1346
|
+
return result;
|
|
1347
|
+
}
|
|
1248
1348
|
}
|
|
1249
1349
|
}
|
|
1250
1350
|
function transformEventHandler(handler, ctx) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constela/compiler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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.
|
|
18
|
+
"@constela/core": "0.14.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@types/node": "^20.10.0",
|