diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-08-13 18:46:16 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-08-13 18:56:10 +0530 |
| commit | 78550c0d1c7037b17bdaa9413351b759b20772c0 (patch) | |
| tree | 2fbef895d94698ec3ec20fe961493748c1a6f1c0 /src | |
| parent | 2f3de513168ac8a912e4b6540907492437a5f834 (diff) | |
| download | css-everything-78550c0d1c7037b17bdaa9413351b759b20772c0.tar.gz css-everything-78550c0d1c7037b17bdaa9413351b759b20772c0.zip | |
feat: adds conditionals
Diffstat (limited to '')
| -rw-r--r-- | src/declarations.ts | 3 | ||||
| -rw-r--r-- | src/eval.ts | 9 | ||||
| -rw-r--r-- | src/index.ts | 3 |
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 } } |
