hastx
Version:
JSX Transform emitting Rehype syntax trees (HAST)
74 lines • 2.07 kB
JavaScript
;
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;
if (tagName === "template") {
return {
type: "element",
tagName,
properties: { ...properties, ...className },
children: [],
content: {
type: "root",
children: read(children),
},
};
}
else {
return {
type: "element",
tagName,
properties: { ...properties, ...className },
children: read(children).filter((child) => child.type !== "doctype"),
};
}
}
else {
return {
type: "root",
children: read(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) {
switch (typeof children) {
case "undefined":
case "boolean":
return [];
case "number":
case "string":
return [{
type: "text",
value: String(children),
}];
default:
if (children === null) {
return [];
}
else if (Array.isArray(children)) {
return children.flatMap(read);
}
else if (children.type === "root") {
return children.children;
}
else {
return [children];
}
}
}
//# sourceMappingURL=jsx-runtime.js.map