Skip to content

Commit

Permalink
chore: update jsx-runtime child handling
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Oct 17, 2022
1 parent 6c27495 commit 4699020
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-dingos-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ultrahtml": patch
---

Update JSX runtime child handling
52 changes: 33 additions & 19 deletions src/jsx-runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
import type { ElementNode, Node } from '../index.js';
import { ELEMENT_NODE, Fragment, __unsafeRenderFn } from '../index.js';
import { ElementNode, Node, TEXT_NODE } from "../index.js";
import { ELEMENT_NODE, Fragment, __unsafeRenderFn } from "../index.js";

function createVNode(type: any, props: Record<string, any>, key: string, __self: string, __source: string) {
const vnode: ElementNode = {
type: ELEMENT_NODE,
name: typeof type === 'function' ? type.name : type,
attributes: props,
children: [],
parent: undefined as any,
loc: [] as any
};
function createVNode(
type: any,
{ children, ...attributes }: Record<string, any>,
key: string,
__self: string,
__source: string
) {
const vnode: ElementNode = {
type: ELEMENT_NODE,
name: typeof type === "function" ? type.name : type,
attributes,
children: (Array.isArray(children) ? children : [children]).map((child) => {
if (typeof child === "string") {
return {
type: TEXT_NODE,
value: child,
};
}
return child;
}),
parent: undefined as any,
loc: [] as any,
};

if (typeof type === 'function') {
__unsafeRenderFn(vnode, type);
}
if (typeof type === "function") {
__unsafeRenderFn(vnode, type);
}

return vnode;
return vnode;
}

export {
createVNode as jsx,
createVNode as jsxs,
createVNode as jsxDEV,
Fragment
createVNode as jsx,
createVNode as jsxs,
createVNode as jsxDEV,
Fragment,
};

0 comments on commit 4699020

Please sign in to comment.