sitegen/framework/engine/jsx-runtime.ts
chloe caruso a8d7efe9ec chore: rework Clover Engine API, remove "SSR" term
"server side rendering" is a misleading term since it implies there is a
server. that isn't neccecarily the case here, since it supports running
in the browser. I think "clover engine" is cute, short for "clover html
rendering engine". Instead of "server side rendering", it's just rendering.

This commit makes things a lot more concise, such as `ssr.ssrAsync`
being renamed to `render.async` to play nicely with namespaced imports.
`getCurrentRender` and `setCurrentRender` are just `current` and
`setCurrent`, and the addon interface has been redesigned to force
symbols with a wrapping helper.
2025-08-02 22:22:07 -04:00

54 lines
1.5 KiB
TypeScript

export const Fragment = ({ children }: { children: render.Node[] }) => children;
export function jsx(
type: string | render.Component,
props: Record<string, unknown>,
): render.Element {
if (typeof type !== "function" && typeof type !== "string") {
throw new Error("Invalid component type: " + render.inspect(type));
}
return [render.kElement, type, props];
}
export function jsxDEV(
type: string | render.Component,
props: Record<string, unknown>,
// Unused with the clover engine
_key: string,
// Unused with the clover engine
_isStaticChildren: boolean,
source: render.SrcLoc,
): render.Element {
const { fileName, lineNumber, columnNumber } = source;
// Assert the component type is valid to render.
if (typeof type !== "function" && typeof type !== "string") {
throw new Error(
`Invalid component type at ${fileName}:${lineNumber}:${columnNumber}: ` +
render.inspect(type) +
". Clover SSR element must be a function or string",
);
}
// Construct an `ssr.Element`
return [render.kElement, type, props, "", source];
}
// jsxs
export { jsx as jsxs };
declare global {
namespace JSX {
interface IntrinsicElements {
[name: string]: Record<string, unknown>;
}
interface ElementChildrenAttribute {
children: Node;
}
type Element = render.Element;
type ElementType = keyof IntrinsicElements | render.Component;
type ElementClass = ReturnType<render.Component>;
}
}
import * as render from "./render.ts";