aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/declarations.ts3
-rw-r--r--src/eval.ts9
-rw-r--r--src/index.ts3
3 files changed, 12 insertions, 3 deletions
diff --git a/src/declarations.ts b/src/declarations.ts
index 17306bd..0571116 100644
--- a/src/declarations.ts
+++ b/src/declarations.ts
@@ -5,6 +5,7 @@ import { match, matchString } from './utils/adt'
export interface Declaration {
selector: Selector
properties: Map<string, Expr>
+ isInstance: boolean
}
export interface DeclarationEval {
@@ -87,7 +88,7 @@ export const toDeclaration = (expr: Expr): Declaration | undefined => {
selector.selectors.push(SelectorComp.Attr(['data-instance', baseId]))
}
- return { selector, properties }
+ return { selector, properties, isInstance }
}
export const expressionsToDeclrs = async (
diff --git a/src/eval.ts b/src/eval.ts
index a70c760..1a55364 100644
--- a/src/eval.ts
+++ b/src/eval.ts
@@ -70,6 +70,15 @@ const getFunctions = (name: string, args: Expr[], actions: EvalActions) =>
}
},
+ if: async () => {
+ const cond = await evalExpr(args[0], actions)
+ const FALSEY = ['0', 'false']
+ if (cond && !FALSEY.includes(cond.replace(/(^'|")|('|"$)/g, ''))) {
+ return evalExpr(args[1], actions)
+ } else {
+ return evalExpr(args[2], actions)
+ }
+ },
delay: async () => {
const num = await evalExpr(args[0], actions)
num && (await actions.delay(parseInt(num, 10)))
diff --git a/src/index.ts b/src/index.ts
index af8eb23..47e65fe 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -210,12 +210,11 @@ export const manageElement = async (
const text = getPropertyValue($element, '--cssx-text')
if (text) {
- const exprs = parse(text)
try {
+ const exprs = parse(text)
$element.textContent =
(exprs[0] ? await evalExpr(exprs[0], actions) : text) ?? text
} catch (e) {
- console.log(e, exprs)
$element.textContent = text
}
}