@almadar/evaluator 2.3.0 → 2.4.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.js +40 -1
- package/dist/index.js.map +1 -1
- package/dist/operators/index.js +15 -1
- package/dist/operators/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -500,10 +500,23 @@ function evalCallService(args, evaluate2, ctx) {
|
|
|
500
500
|
console.error(`Service call ${service}.${method} failed:`, err);
|
|
501
501
|
});
|
|
502
502
|
}
|
|
503
|
+
function evaluateNestedProps(obj, evaluate2, ctx) {
|
|
504
|
+
const result = {};
|
|
505
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
506
|
+
if (Array.isArray(value) && value.length > 0 && typeof value[0] === "string") {
|
|
507
|
+
result[key] = evaluate2(value, ctx);
|
|
508
|
+
} else if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
509
|
+
result[key] = evaluateNestedProps(value, evaluate2, ctx);
|
|
510
|
+
} else {
|
|
511
|
+
result[key] = value;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return result;
|
|
515
|
+
}
|
|
503
516
|
function evalRenderUI(args, evaluate2, ctx) {
|
|
504
517
|
const slot = args[0];
|
|
505
518
|
const pattern = evaluate2(args[1], ctx);
|
|
506
|
-
const
|
|
519
|
+
const rawProps = args.length > 2 ? args[2] : void 0;
|
|
507
520
|
const priority = args.length > 3 ? evaluate2(args[3], ctx) : void 0;
|
|
508
521
|
if (!ctx.renderUI) {
|
|
509
522
|
console.warn("No renderUI handler in context for render-ui effect");
|
|
@@ -513,6 +526,7 @@ function evalRenderUI(args, evaluate2, ctx) {
|
|
|
513
526
|
ctx.renderUI(slot, { type: "clear" }, void 0, priority);
|
|
514
527
|
return;
|
|
515
528
|
}
|
|
529
|
+
const props = rawProps ? evaluateNestedProps(rawProps, evaluate2, ctx) : void 0;
|
|
516
530
|
ctx.renderUI(slot, pattern, props, priority);
|
|
517
531
|
}
|
|
518
532
|
function evalSetDynamic(args, evaluate2, ctx) {
|
|
@@ -809,6 +823,28 @@ function evalWithItem(expr, evaluate2, ctx, item, index) {
|
|
|
809
823
|
const locals = /* @__PURE__ */ new Map();
|
|
810
824
|
locals.set("item", item);
|
|
811
825
|
locals.set("index", index);
|
|
826
|
+
if (isSExpr(expr)) {
|
|
827
|
+
const op = getOperator(expr);
|
|
828
|
+
if (op === "fn" || op === "lambda") {
|
|
829
|
+
const fnArgs = getArgs(expr);
|
|
830
|
+
const params = fnArgs[0];
|
|
831
|
+
const body = fnArgs[1];
|
|
832
|
+
if (typeof params === "string") {
|
|
833
|
+
const key = params.startsWith("@") ? params.slice(1) : params;
|
|
834
|
+
locals.set(key, item);
|
|
835
|
+
} else if (Array.isArray(params)) {
|
|
836
|
+
const paramNames = params;
|
|
837
|
+
const values = [item, index];
|
|
838
|
+
for (let i = 0; i < paramNames.length; i++) {
|
|
839
|
+
const p = paramNames[i];
|
|
840
|
+
const key = p.startsWith("@") ? p.slice(1) : p;
|
|
841
|
+
locals.set(key, values[i]);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
const childCtx2 = createChildContext(ctx, locals);
|
|
845
|
+
return evaluate2(body, childCtx2);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
812
848
|
const childCtx = createChildContext(ctx, locals);
|
|
813
849
|
return evaluate2(expr, childCtx);
|
|
814
850
|
}
|
|
@@ -2451,6 +2487,9 @@ var SExpressionEvaluator = class {
|
|
|
2451
2487
|
return evalDo(args, evaluate2, ctx);
|
|
2452
2488
|
case "when":
|
|
2453
2489
|
return evalWhen(args, evaluate2, ctx);
|
|
2490
|
+
case "fn":
|
|
2491
|
+
case "lambda":
|
|
2492
|
+
return evalFn(args);
|
|
2454
2493
|
// Collections
|
|
2455
2494
|
case "map":
|
|
2456
2495
|
return evalMap(args, evaluate2, ctx);
|