@almadar/evaluator 2.3.1 → 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 +25 -0
- package/dist/index.js.map +1 -1
- package/package.json +9 -11
package/dist/index.js
CHANGED
|
@@ -823,6 +823,28 @@ function evalWithItem(expr, evaluate2, ctx, item, index) {
|
|
|
823
823
|
const locals = /* @__PURE__ */ new Map();
|
|
824
824
|
locals.set("item", item);
|
|
825
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
|
+
}
|
|
826
848
|
const childCtx = createChildContext(ctx, locals);
|
|
827
849
|
return evaluate2(expr, childCtx);
|
|
828
850
|
}
|
|
@@ -2465,6 +2487,9 @@ var SExpressionEvaluator = class {
|
|
|
2465
2487
|
return evalDo(args, evaluate2, ctx);
|
|
2466
2488
|
case "when":
|
|
2467
2489
|
return evalWhen(args, evaluate2, ctx);
|
|
2490
|
+
case "fn":
|
|
2491
|
+
case "lambda":
|
|
2492
|
+
return evalFn(args);
|
|
2468
2493
|
// Collections
|
|
2469
2494
|
case "map":
|
|
2470
2495
|
return evalMap(args, evaluate2, ctx);
|