Skip to content

Instantly share code, notes, and snippets.

@jed
Created October 18, 2025 22:57
Show Gist options
  • Select an option

  • Save jed/315c9ebc45dd194c80bb3b7c97a3f9c9 to your computer and use it in GitHub Desktop.

Select an option

Save jed/315c9ebc45dd194c80bb3b7c97a3f9c9 to your computer and use it in GitHub Desktop.
jsx → html
{
"imports": {
"./jsx-runtime": "./jsx-runtime.js"
},
"compilerOptions": {
"jsx": "react-jsx",
"jsxImportSource": "."
}
}
const VOID = new Set([
"area",
"base",
"br",
"col",
"embed",
"hr",
"img",
"input",
"link",
"meta",
"param",
"source",
"track",
"wbr",
]);
const jsx = (node, props) =>
(function* (node, { children, ...attrs } = {}) {
if (node === jsx) return yield* children;
if (typeof node === "function") yield* node(props);
yield `<${node}`;
for (const key in attrs) yield ` ${key}="${attrs[key]}"`;
yield `>`;
if (VOID.has(node)) return;
Array.isArray(children) ? yield* children : yield children;
yield `</${node}>`;
})(node, props).reduce((a, b) => a + b);
export { jsx, jsx as jsxs, jsx as Fragment };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment