-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update jsx-runtime child handling
- Loading branch information
1 parent
6c27495
commit 4699020
Showing
2 changed files
with
38 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"ultrahtml": patch | ||
--- | ||
|
||
Update JSX runtime child handling |
This file contains 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
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, | ||
}; |