expect(normalizeVNode(null)).toMatchObject({ type: Comment })
expect(normalizeVNode(undefined)).toMatchObject({ type: Comment })
+ // boolean -> Comment
+ // this is for usage like `someBoolean && h('div')` and behavior consistency
+ // with 2.x (#574)
+ expect(normalizeVNode(true)).toMatchObject({ type: Comment })
+ expect(normalizeVNode(false)).toMatchObject({ type: Comment })
+
// array -> Fragment
expect(normalizeVNode(['foo'])).toMatchObject({ type: Fragment })
// primitive types
expect(normalizeVNode('foo')).toMatchObject({ type: Text, children: `foo` })
expect(normalizeVNode(1)).toMatchObject({ type: Text, children: `1` })
- expect(normalizeVNode(true)).toMatchObject({ type: Text, children: `true` })
})
test('type shapeFlag inference', () => {
}
export function normalizeVNode<T, U>(child: VNodeChild<T, U>): VNode<T, U> {
- if (child == null) {
+ if (child == null || typeof child === 'boolean') {
// empty placeholder
return createVNode(Comment)
} else if (isArray(child)) {
// always produce all-vnode children arrays
return child.el === null ? child : cloneVNode(child)
} else {
- // primitive types
+ // strings and numbers
return createVNode(Text, null, String(child))
}
}