sitegen/framework/engine/jsx-runtime.ts

55 lines
1.5 KiB
TypeScript
Raw Normal View History

export const Fragment = ({ children }: { children: render.Node[] }) => children;
2025-07-07 20:58:02 -07:00
export function jsx(
type: string | render.Component,
2025-07-07 20:58:02 -07:00
props: Record<string, unknown>,
): render.Element {
2025-07-07 20:58:02 -07:00
if (typeof type !== "function" && typeof type !== "string") {
throw new Error("Invalid component type: " + render.inspect(type));
2025-07-07 20:58:02 -07:00
}
return [render.kElement, type, props];
2025-07-07 20:58:02 -07:00
}
export function jsxDEV(
type: string | render.Component,
2025-07-07 20:58:02 -07:00
props: Record<string, unknown>,
// Unused with the clover engine
_key: string,
// Unused with the clover engine
_isStaticChildren: boolean,
source: render.SrcLoc,
): render.Element {
2025-07-07 20:58:02 -07:00
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) +
2025-07-07 20:58:02 -07:00
". Clover SSR element must be a function or string",
);
}
// Construct an `ssr.Element`
return [render.kElement, type, props, "", source];
2025-07-07 20:58:02 -07:00
}
// 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>;
2025-07-07 20:58:02 -07:00
}
}
import * as render from "#engine/render";