Skip to content

Commit 6918436

Browse files
defccyyx990803
authored andcommitted
Update normalize children (fix 4466) (vuejs#4468)
* omit boolean node * add test case * update boolean type * update test case * update test case
1 parent 5300e71 commit 6918436

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/core/vdom/helpers/normalize-children.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
1616
let i, c, last
1717
for (i = 0; i < children.length; i++) {
1818
c = children[i]
19-
if (c == null) continue
19+
if (c == null || typeof c === 'boolean') continue
2020
last = res[res.length - 1]
2121
// nested
2222
if (Array.isArray(c)) {

test/unit/modules/vdom/create-element.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ describe('create-element', () => {
9898
expect(vnode.children[2].tag).toBe('br')
9999
})
100100

101+
it('render vnode with children, including boolean and null type', () => {
102+
const vm = new Vue({})
103+
const h = vm.$createElement
104+
const vnode = h('p', [h('br'), true, 123, h('br'), 'abc', null])
105+
expect(vnode.children.length).toBe(4)
106+
expect(vnode.children[0].tag).toBe('br')
107+
expect(vnode.children[1].text).toBe('123')
108+
expect(vnode.children[2].tag).toBe('br')
109+
expect(vnode.children[3].text).toBe('abc')
110+
})
111+
101112
it('render svg elements with correct namespace', () => {
102113
const vm = new Vue({})
103114
const h = vm.$createElement

0 commit comments

Comments
 (0)