aboutsummaryrefslogtreecommitdiff
path: root/src/eval.ts
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-08-13 18:35:31 +0530
committerAkshay Nair <phenax5@gmail.com>2023-08-13 18:35:31 +0530
commit2f3de513168ac8a912e4b6540907492437a5f834 (patch)
tree957c286eb8b0806d82279d7596f5f47425d3a9a8 /src/eval.ts
parent95602d1b1ac5668772d5d400270b4209ee19057b (diff)
downloadcss-everything-2f3de513168ac8a912e4b6540907492437a5f834.tar.gz
css-everything-2f3de513168ac8a912e4b6540907492437a5f834.zip
feat: adds checked test case + implements pure actions flag + minor changes
Diffstat (limited to 'src/eval.ts')
-rw-r--r--src/eval.ts19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/eval.ts b/src/eval.ts
index 79eeb79..a70c760 100644
--- a/src/eval.ts
+++ b/src/eval.ts
@@ -8,7 +8,11 @@ export interface EvalActions {
jsEval(js: string): Promise<any>
loadCssx(id: string, url: string): Promise<string>
getVariable(name: string): Promise<string | undefined>
- updateVariable(id: string, varName: string, value: string): Promise<void>
+ updateVariable(
+ id: string | undefined,
+ varName: string,
+ value: string,
+ ): Promise<void>
getAttribute(
id: string | undefined,
name: string,
@@ -89,11 +93,12 @@ const getFunctions = (name: string, args: Expr[], actions: EvalActions) =>
return varName && (actions.getVariable(varName) ?? defaultValue)
},
update: async () => {
- const id = await evalExpr(args[0], actions)
- const varName = await evalExpr(args[1], actions)
- const value = await evalExpr(args[2], actions)
- if (id && varName && value) {
- actions.updateVariable(id, varName, value)
+ const [id, name, value] =
+ args.length >= 3
+ ? await evalArgs(args, 3, actions)
+ : [undefined, ...(await evalArgs(args, 2, actions))]
+ if (name) {
+ actions.updateVariable(id ?? undefined, name, value ?? '')
}
},
@@ -103,7 +108,7 @@ const getFunctions = (name: string, args: Expr[], actions: EvalActions) =>
? await evalArgs(args, 3, actions)
: [undefined, ...(await evalArgs(args, 2, actions))]
if (name) {
- actions.setAttribute(id as string | undefined, name, value ?? '')
+ actions.setAttribute(id ?? undefined, name, value ?? '')
}
},
attr: async () => {