UNPKG

hastx

Version:

JSX Transform emitting Rehype syntax trees (HAST)

52 lines 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.jsxDEV = exports.jsxs = void 0; exports.jsx = jsx; exports.Fragment = Fragment; 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 } : {}) }); } } exports.jsxs = jsx; exports.jsxDEV = jsx; 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