diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-08-25 12:14:42 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-08-25 12:14:42 +0530 |
| commit | ca0737e393bbf5c45f688593bbfaf41079a66784 (patch) | |
| tree | f3de7e5ce2bbd022fabd50db23bd54a240a89735 /src/declarations.ts | |
| parent | f7ea49c88717c0c15835c9024c84a95678836a30 (diff) | |
| download | css-everything-ca0737e393bbf5c45f688593bbfaf41079a66784.tar.gz css-everything-ca0737e393bbf5c45f688593bbfaf41079a66784.zip | |
feat: h expressions for declaring elements
Diffstat (limited to 'src/declarations.ts')
| -rw-r--r-- | src/declarations.ts | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/src/declarations.ts b/src/declarations.ts index a82f42f..5725846 100644 --- a/src/declarations.ts +++ b/src/declarations.ts @@ -30,9 +30,40 @@ export const toDeclaration = }, Call: async ({ name, args }) => { return matchString(name, { - // h: () => { - // - // }, + h: async () => { + const [sel, map, childreExpr] = args + + // Selector + match(sel, { + Selector: sel => { + selector = sel + }, + _: _ => {}, + }) + + const props = await evalExpr(map, actions) + match(props, { + Map: props => { + for (const [key, value] of Object.entries(props)) { + properties.set(key, value) + } + }, + _: _ => {}, + }) + + const childrenExprs = await match< + Promise<Array<Declaration | undefined>>, + EvalValue + >(await evalExpr(childreExpr, actions), { + Lazy: async exprs => + Promise.all(exprs.map(toDeclaration(actions))), + _: async _ => [], + }) + + children.push( + ...(childrenExprs.filter(Boolean) as Array<Declaration>), + ) + }, instance: async () => { isInstance = true const [sel, map] = args |
