From f3a77cb2f83ff2f91a5cc78da2bd735ad0d4edec Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 12 Jan 2025 19:09:39 +0900 Subject: refactor(blog/nuldoc): support JSX notation in nuldoc sources --- vhosts/blog/nuldoc-src/jsx/jsx-runtime.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 vhosts/blog/nuldoc-src/jsx/jsx-runtime.ts (limited to 'vhosts/blog/nuldoc-src/jsx/jsx-runtime.ts') diff --git a/vhosts/blog/nuldoc-src/jsx/jsx-runtime.ts b/vhosts/blog/nuldoc-src/jsx/jsx-runtime.ts new file mode 100644 index 00000000..9571e87d --- /dev/null +++ b/vhosts/blog/nuldoc-src/jsx/jsx-runtime.ts @@ -0,0 +1,27 @@ +import type { Node } from "../dom.ts"; + +export type JSXElement = { + tag: string | FunctionComponent; + props: Props; +}; + +export type JSXNullNode = false | null | undefined; +export type JSXSimpleNode = JSXElement | Node | string; +export type JSXNullableSimpleNode = JSXSimpleNode | JSXNullNode; +export type JSXNode = JSXNullableSimpleNode | JSXNode[]; +export type RenderableJSXNode = JSXElement; + +type Props = { children?: JSXNode } & Record; +export type FunctionComponentResult = JSXElement | Promise; +type FunctionComponent = (props: Props) => FunctionComponentResult; + +export function jsx( + tag: string | FunctionComponent, + props: Props, +): JSXElement { + return { tag, props }; +} + +export { jsx as jsxs }; + +// TODO: support Fragment -- cgit v1.2.3-70-g09d2