Skip to content
Permalink
Browse files
fix: fix single v-for child optimization
  • Loading branch information
yyx990803 committed Dec 11, 2018
1 parent 4e97548 commit 847e493768371cec4718969e02bdb7f8463f4e03
@@ -32,8 +32,9 @@ export function renderList (
ret[i] = render(val[key], key, i)
}
}
if (isDef(ret)) {
(ret: any)._isVList = true
if (!isDef(ret)) {
ret = []
}
(ret: any)._isVList = true
return ret
}
@@ -16,9 +16,6 @@ import { isFalse, isTrue, isDef, isUndef, isPrimitive } from 'shared/util'
// thing with Array.prototype.concat. It is guaranteed to be only 1-level deep
// because functional components already normalize their own children.
export function simpleNormalizeChildren (children: any) {
if (!Array.isArray(children)) {
return
}
for (let i = 0; i < children.length; i++) {
if (Array.isArray(children[i])) {
return Array.prototype.concat.apply([], children)
@@ -489,7 +489,7 @@ describe('Directive v-for', () => {
const vm = new Vue({
template:
'<div attr>' +
'<foo v-for="item in list">{{ item }}</foo>' +
'<foo v-for="item in list" :key="item">{{ item }}</foo>' +
'</div>',
data: {
list: undefined
@@ -507,6 +507,23 @@ describe('Directive v-for', () => {
}).then(done)
})

it('elements with v-for and empty list', done => {
const vm = new Vue({
template:
'<div attr>' +
'<div v-for="item in list">{{ item }}</div>' +
'</div>',
data: {
list: undefined
}
}).$mount()
expect(vm.$el.innerHTML).toBe('')
vm.list = [1, 2, 3]
waitForUpdate(() => {
expect(vm.$el.innerHTML).toBe('<div>1</div><div>2</div><div>3</div>')
}).then(done)
})

const supportsDestructuring = (() => {
try {
new Function('var { foo } = bar')

0 comments on commit 847e493

Please sign in to comment.