Skip to content

Commit 54d06ec

Browse files
committed
feat(runtime-core): support variadic children in h for simple JSX compat
ref: #1917
1 parent 6602d6d commit 54d06ec

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/runtime-core/__tests__/h.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,20 @@ describe('renderer: h', () => {
6464
})
6565
)
6666
})
67+
68+
// for simple JSX compat
69+
// note this signature is not supported in types; it's purely for usage with
70+
// compiled code.
71+
test('support variadic children', () => {
72+
// @ts-ignore
73+
const vnode = h('div', null, h('span'), h('span'))
74+
expect(vnode.children).toMatchObject([
75+
{
76+
type: 'span'
77+
},
78+
{
79+
type: 'span'
80+
}
81+
])
82+
})
6783
})

packages/runtime-core/src/h.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ export function h<P>(
129129

130130
// Actual implementation
131131
export function h(type: any, propsOrChildren?: any, children?: any): VNode {
132-
if (arguments.length === 2) {
132+
const l = arguments.length
133+
if (l === 2) {
133134
if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
134135
// single vnode without props
135136
if (isVNode(propsOrChildren)) {
@@ -142,7 +143,9 @@ export function h(type: any, propsOrChildren?: any, children?: any): VNode {
142143
return createVNode(type, null, propsOrChildren)
143144
}
144145
} else {
145-
if (isVNode(children)) {
146+
if (l > 3) {
147+
children = Array.prototype.slice.call(arguments, 2)
148+
} else if (l === 3 && isVNode(children)) {
146149
children = [children]
147150
}
148151
return createVNode(type, propsOrChildren, children)

0 commit comments

Comments
 (0)