Created
October 18, 2025 22:57
-
-
Save jed/315c9ebc45dd194c80bb3b7c97a3f9c9 to your computer and use it in GitHub Desktop.
jsx → html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "imports": { | |
| "./jsx-runtime": "./jsx-runtime.js" | |
| }, | |
| "compilerOptions": { | |
| "jsx": "react-jsx", | |
| "jsxImportSource": "." | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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