From 6411d58b48682c65165a1e717a9bf837737887f3 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 13 Aug 2023 21:12:14 +0530 Subject: fix: get-var hack --- src/eval.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/eval.ts') diff --git a/src/eval.ts b/src/eval.ts index 1a55364..445cb8f 100644 --- a/src/eval.ts +++ b/src/eval.ts @@ -53,8 +53,14 @@ export const evalExpr = async ( _: async _ => undefined, }) -const getFunctions = (name: string, args: Expr[], actions: EvalActions) => - matchString>(name, { +const getFunctions = (name: string, args: Expr[], actions: EvalActions) => { + const getVariable = async () => { + const varName = await evalExpr(args[0], actions) + const defaultValue = args[1] && (await evalExpr(args[1], actions)) + return varName && (actions.getVariable(varName) ?? defaultValue) + } + + return matchString>(name, { 'add-class': async () => { const id = await evalExpr(args[0], actions) const classes = await evalExpr(args[1], actions) @@ -96,11 +102,9 @@ const getFunctions = (name: string, args: Expr[], actions: EvalActions) => } }, - var: async () => { - const varName = await evalExpr(args[0], actions) - const defaultValue = args[1] && (await evalExpr(args[1], actions)) - return varName && (actions.getVariable(varName) ?? defaultValue) - }, + var: getVariable, + 'get-var': getVariable, + update: async () => { const [id, name, value] = args.length >= 3 @@ -153,6 +157,7 @@ const getFunctions = (name: string, args: Expr[], actions: EvalActions) => _: () => Promise.reject(new Error('not supposed to be here')), }) +} export const evalArgs = ( args: Array, -- cgit v1.3.1