aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--TODO.norg4
-rw-r--r--src/eval.ts26
2 files changed, 22 insertions, 8 deletions
diff --git a/TODO.norg b/TODO.norg
index 3d052cf..348b06f 100644
--- a/TODO.norg
+++ b/TODO.norg
@@ -6,8 +6,8 @@
- (x) analog + digital clock example
- (x) error handling try
- (x) Scoped catch on try
- - ( ) `do` expression
- - ( ) `let` expression
+ - (x) `do` expression
+ - (x) `let` expression
- ( ) `has-class`
- ( ) `add-class` & `remove-class` should use self if id is not specified?
- ( ) Update `--cssx-text` on update
diff --git a/src/eval.ts b/src/eval.ts
index 1b5aace..2dde4c1 100644
--- a/src/eval.ts
+++ b/src/eval.ts
@@ -130,6 +130,13 @@ const getFunctions = (
})
}
+ const jsEval = async () => {
+ const js = await evalExprAsString(args[0], actions)
+ const result = js && (await actions.jsEval(js))
+ if (result === undefined || result === null) return EvalValue.Void()
+ return EvalValue.Value(result)
+ }
+
return matchString<Promise<EvalValue>>(name, {
'add-class': async () => {
const id = evalValueToString(await evalExpr(args[0], actions))
@@ -161,12 +168,9 @@ const getFunctions = (
num !== undefined ? await actions.delay(num) : undefined
return EvalValue.Void()
},
- 'js-eval': async () => {
- const js = await evalExprAsString(args[0], actions)
- const result = js && (await actions.jsEval(js))
- if (result === undefined || result === null) return EvalValue.Void()
- return EvalValue.Value(result)
- },
+
+ 'js-eval': jsEval,
+ 'js-expr': jsEval,
'load-cssx': async () => {
const id = evalValueToString(await evalExpr(args[0], actions))
@@ -340,6 +344,16 @@ const getFunctions = (
return result
},
+ let: async () => {
+ const varName = await evalExprAsString(args[0], actions)
+ const result = await evalExpr(args[1], actions)
+ if (!varName) return EvalValue.Void()
+
+ return actions.evaluateInScope([args[2]], {
+ [varName]: result,
+ })
+ },
+
_: () => Promise.reject(new Error(`Not implemented: ${name}`)),
})
}