feat(runtime-core): support variadic children in h
for simple JSX compat
ref: #1917
This commit is contained in:
parent
6602d6dbff
commit
54d06ec495
@ -64,4 +64,20 @@ describe('renderer: h', () => {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// for simple JSX compat
|
||||||
|
// note this signature is not supported in types; it's purely for usage with
|
||||||
|
// compiled code.
|
||||||
|
test('support variadic children', () => {
|
||||||
|
// @ts-ignore
|
||||||
|
const vnode = h('div', null, h('span'), h('span'))
|
||||||
|
expect(vnode.children).toMatchObject([
|
||||||
|
{
|
||||||
|
type: 'span'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'span'
|
||||||
|
}
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -129,7 +129,8 @@ export function h<P>(
|
|||||||
|
|
||||||
// Actual implementation
|
// Actual implementation
|
||||||
export function h(type: any, propsOrChildren?: any, children?: any): VNode {
|
export function h(type: any, propsOrChildren?: any, children?: any): VNode {
|
||||||
if (arguments.length === 2) {
|
const l = arguments.length
|
||||||
|
if (l === 2) {
|
||||||
if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
|
if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
|
||||||
// single vnode without props
|
// single vnode without props
|
||||||
if (isVNode(propsOrChildren)) {
|
if (isVNode(propsOrChildren)) {
|
||||||
@ -142,7 +143,9 @@ export function h(type: any, propsOrChildren?: any, children?: any): VNode {
|
|||||||
return createVNode(type, null, propsOrChildren)
|
return createVNode(type, null, propsOrChildren)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isVNode(children)) {
|
if (l > 3) {
|
||||||
|
children = Array.prototype.slice.call(arguments, 2)
|
||||||
|
} else if (l === 3 && isVNode(children)) {
|
||||||
children = [children]
|
children = [children]
|
||||||
}
|
}
|
||||||
return createVNode(type, propsOrChildren, children)
|
return createVNode(type, propsOrChildren, children)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user