File tree Expand file tree Collapse file tree 2 files changed +27
-4
lines changed
test/unit/features/directives Expand file tree Collapse file tree 2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -298,14 +298,18 @@ function genChildren (el: ASTElement, checkSkip?: boolean): string | void {
298
298
function canSkipNormalization ( children ) : boolean {
299
299
for ( let i = 0 ; i < children . length ; i ++ ) {
300
300
const el : any = children [ i ]
301
- if ( el . for || el . tag === 'template' || el . tag === 'slot' ||
302
- ( el . if && el . ifConditions . some ( c => c . tag === 'template' ) ) ) {
301
+ if ( needsNormalization ( el ) ||
302
+ ( el . if && el . ifConditions . some ( c => needsNormalization ( c . block ) ) ) ) {
303
303
return false
304
304
}
305
305
}
306
306
return true
307
307
}
308
308
309
+ function needsNormalization ( el ) {
310
+ return el . for || el . tag === 'template' || el . tag === 'slot'
311
+ }
312
+
309
313
function genNode ( node : ASTNode ) {
310
314
if ( node . type === 1 ) {
311
315
return genElement ( node )
Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ describe('Directive v-if', () => {
141
141
const vm = new Vue ( {
142
142
template : `
143
143
<div>
144
- <span v-for="item,i in list" v-if="item.value">{{i}}</span>
144
+ <span v-for="( item, i) in list" v-if="item.value">{{i}}</span>
145
145
</div>
146
146
` ,
147
147
data : {
@@ -169,7 +169,7 @@ describe('Directive v-if', () => {
169
169
const vm = new Vue ( {
170
170
template : `
171
171
<div>
172
- <span v-for="item,i in list" v-if="item.value">hello</span>
172
+ <span v-for="( item, i) in list" v-if="item.value">hello</span>
173
173
<span v-else>bye</span>
174
174
</div>
175
175
` ,
@@ -194,6 +194,25 @@ describe('Directive v-if', () => {
194
194
} ) . then ( done )
195
195
} )
196
196
197
+ it ( 'should work with v-for on v-else branch' , done => {
198
+ const vm = new Vue ( {
199
+ template : `
200
+ <div>
201
+ <span v-if="false">hello</span>
202
+ <span v-else v-for="item in list">{{ item }}</span>
203
+ </div>
204
+ ` ,
205
+ data : {
206
+ list : [ 1 , 2 , 3 ]
207
+ }
208
+ } ) . $mount ( )
209
+ expect ( vm . $el . textContent . trim ( ) ) . toBe ( '123' )
210
+ vm . list . reverse ( )
211
+ waitForUpdate ( ( ) => {
212
+ expect ( vm . $el . textContent . trim ( ) ) . toBe ( '321' )
213
+ } ) . then ( done )
214
+ } )
215
+
197
216
it ( 'should work properly on component root' , done => {
198
217
const vm = new Vue ( {
199
218
template : `
You can’t perform that action at this time.
0 commit comments