|
@ -54,25 +54,25 @@ describe('codegen', () => { |
|
|
it('generate v-for directive', () => { |
|
|
it('generate v-for directive', () => { |
|
|
assertCodegen( |
|
|
assertCodegen( |
|
|
'<div><li v-for="item in items" :key="item.uid"></li></div>', |
|
|
'<div><li v-for="item in items" :key="item.uid"></li></div>', |
|
|
`with(this){return _c('div',_l((items),function(item){return _c('li',{key:item.uid})}))}` |
|
|
`with(this){return _c('div',_l((items),function(item){return _c('li',{key:item.uid})}),0)}` |
|
|
) |
|
|
) |
|
|
// iterator syntax
|
|
|
// iterator syntax
|
|
|
assertCodegen( |
|
|
assertCodegen( |
|
|
'<div><li v-for="(item, i) in items"></li></div>', |
|
|
'<div><li v-for="(item, i) in items"></li></div>', |
|
|
`with(this){return _c('div',_l((items),function(item,i){return _c('li')}))}` |
|
|
`with(this){return _c('div',_l((items),function(item,i){return _c('li')}),0)}` |
|
|
) |
|
|
) |
|
|
assertCodegen( |
|
|
assertCodegen( |
|
|
'<div><li v-for="(item, key, index) in items"></li></div>', |
|
|
'<div><li v-for="(item, key, index) in items"></li></div>', |
|
|
`with(this){return _c('div',_l((items),function(item,key,index){return _c('li')}))}` |
|
|
`with(this){return _c('div',_l((items),function(item,key,index){return _c('li')}),0)}` |
|
|
) |
|
|
) |
|
|
// destructuring
|
|
|
// destructuring
|
|
|
assertCodegen( |
|
|
assertCodegen( |
|
|
'<div><li v-for="{ a, b } in items"></li></div>', |
|
|
'<div><li v-for="{ a, b } in items"></li></div>', |
|
|
`with(this){return _c('div',_l((items),function({ a, b }){return _c('li')}))}` |
|
|
`with(this){return _c('div',_l((items),function({ a, b }){return _c('li')}),0)}` |
|
|
) |
|
|
) |
|
|
assertCodegen( |
|
|
assertCodegen( |
|
|
'<div><li v-for="({ a, b }, key, index) in items"></li></div>', |
|
|
'<div><li v-for="({ a, b }, key, index) in items"></li></div>', |
|
|
`with(this){return _c('div',_l((items),function({ a, b },key,index){return _c('li')}))}` |
|
|
`with(this){return _c('div',_l((items),function({ a, b },key,index){return _c('li')}),0)}` |
|
|
) |
|
|
) |
|
|
// v-for with extra element
|
|
|
// v-for with extra element
|
|
|
assertCodegen( |
|
|
assertCodegen( |
|
@ -126,7 +126,7 @@ describe('codegen', () => { |
|
|
it('generate ref on v-for', () => { |
|
|
it('generate ref on v-for', () => { |
|
|
assertCodegen( |
|
|
assertCodegen( |
|
|
'<ul><li v-for="item in items" ref="component1"></li></ul>', |
|
|
'<ul><li v-for="item in items" ref="component1"></li></ul>', |
|
|
`with(this){return _c('ul',_l((items),function(item){return _c('li',{ref:"component1",refInFor:true})}))}` |
|
|
`with(this){return _c('ul',_l((items),function(item){return _c('li',{ref:"component1",refInFor:true})}),0)}` |
|
|
) |
|
|
) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
@ -597,7 +597,7 @@ describe('codegen', () => { |
|
|
it('generate static trees inside v-for', () => { |
|
|
it('generate static trees inside v-for', () => { |
|
|
assertCodegen( |
|
|
assertCodegen( |
|
|
`<div><div v-for="i in 10"><p><span></span></p></div></div>`, |
|
|
`<div><div v-for="i in 10"><p><span></span></p></div></div>`, |
|
|
`with(this){return _c('div',_l((10),function(i){return _c('div',[_m(0,true)])}))}`, |
|
|
`with(this){return _c('div',_l((10),function(i){return _c('div',[_m(0,true)])}),0)}`, |
|
|
[`with(this){return _c('p',[_c('span')])}`] |
|
|
[`with(this){return _c('p',[_c('span')])}`] |
|
|
) |
|
|
) |
|
|
}) |
|
|
}) |
|
|