UNPKG

hastx

Version:

JSX Transform emitting Rehype syntax trees (HAST)

47 lines 1.35 kB
export function jsx(type, props, key) { if (typeof type === "string") { let tagName = type; let { children, ...properties } = props; let className = properties.class ? { className: properties.class } : null; return { type: "element", tagName, properties: { ...properties, ...className }, children: read(children), }; } else { return type({ ...props, ...(key ? { key } : {}) }); } } export const jsxs = jsx; export const jsxDEV = jsx; export function Fragment(props) { let { children = [] } = props; return { type: "root", children: read(children), }; } function read(children) { let nodes = Array.isArray(children) ? children : (children ? [children] : []); return nodes.flatMap((child) => { switch (typeof child) { case "number": case "boolean": case "string": return [{ type: "text", value: String(child), }]; default: if (child.type === "root") { return child.children; } else { return [child]; } } }); } //# sourceMappingURL=jsx-runtime.js.map