initial jsx support

This commit is contained in:
laura 2025-11-01 14:50:30 -03:00
parent 2301c5d631
commit 11be5e979c
Signed by: w
GPG key ID: BCD2117C99E69817
7 changed files with 77 additions and 30 deletions

29
src/jsx.ts Normal file
View file

@ -0,0 +1,29 @@
/**
* Copyright (c) 2025 xwra
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { html, type HtmlProxy } from "./html.ts";
import { ChunkedStream } from "./stream.ts";
let context;
export function jsx(
tag: string | typeof Fragment,
{ children }: Record<string, any> = {},
) {
return async (chunks: ChunkedStream<string>) => {
if (tag === Fragment) {
context = html(chunks);
for (const child of children) {
await context.render?.(child);
}
return;
}
await (context ||= html(chunks))[tag](...children);
};
}
export const Fragment = Symbol("Fragment");
export const jsxs = jsx;