提交 7691d888 编写于 作者: fxy060608's avatar fxy060608

fix(v3): v-for without child element #1206

上级 3b0364a1
......@@ -61,15 +61,19 @@ describe('codegen', () => {
assertCodegen(
'<div><template v-for="item in items"><span v-if="item.sub"></span></template></div>',
`with(this){return _c('div',[_l((_$s(1,'f',{forItems:items})),function(item,$10,$20,$30){return [(_$s(("2-"+$30),'i',item.sub))?_c('span',{key:_$s(1,'f',{forIndex:$20,keyIndex:0,key:1+'-0'+$30})}):_e()]})],2)}`
)
assertCodegen(
'<view><template v-for="(item, index) in arr">{{item}}</template></view>',
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(item))))]})],2)}`
)
assertCodegen(
'<view><block v-for="(item, index) in arr" v-bind:key="index">{{item}}</block></view>',
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(item))))]})],2)}`
)
)
assertCodegen(
'<view><template v-for="(item, index) in arr">{{item}}</template></view>',
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(item))))]})],2)}`
)
assertCodegen(
'<view><block v-for="(item, index) in arr" v-bind:key="index">{{item}}</block></view>',
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [_v((_$s(("1-"+$30),'t0',_s(item))))]})],2)}`
)
assertCodegen(
'<view><block v-for="(item,index) in arr" v-bind:key="index"><block v-if="item==3">{{item}}</block></block></view>',
`with(this){return _c('view',[_l((_$s(1,'f',{forItems:arr,fill:true})),function(item,index,$20,$30){return [(_$s(("2-"+$30),'i',item==3))?[_v((_$s(("2-"+$30),'t0',_s(item))))]:_e()]})],2)}`
)
})
it('generate text with multiple statements', () => {
assertCodegen(
......
......@@ -92,7 +92,11 @@ function checkAutoFill (el) {
el.tag === 'template' ||
el.tag === 'block'
) &&
!el.children.find(child => child.type === 1)
!el.children.find(child =>
child.type === 1 &&
child.tag !== 'template' &&
child.tag !== 'block'
)
) {
return true
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册