mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-05 05:27:59 +08:00
perf: skip normalization on single child element v-for
This commit is contained in:
parent
47487607fb
commit
4074104fac
@ -406,7 +406,9 @@ export function genChildren (
|
||||
el.tag !== 'template' &&
|
||||
el.tag !== 'slot'
|
||||
) {
|
||||
const normalizationType = checkSkip && state.maybeComponent(el) ? `,1` : ``
|
||||
const normalizationType = checkSkip
|
||||
? state.maybeComponent(el) ? `,1` : `,0`
|
||||
: ``
|
||||
return `${(altGenElement || genElement)(el, state)}${normalizationType}`
|
||||
}
|
||||
const normalizationType = checkSkip
|
||||
|
@ -54,25 +54,25 @@ describe('codegen', () => {
|
||||
it('generate v-for directive', () => {
|
||||
assertCodegen(
|
||||
'<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
|
||||
assertCodegen(
|
||||
'<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(
|
||||
'<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
|
||||
assertCodegen(
|
||||
'<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(
|
||||
'<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
|
||||
assertCodegen(
|
||||
@ -126,7 +126,7 @@ describe('codegen', () => {
|
||||
it('generate ref on v-for', () => {
|
||||
assertCodegen(
|
||||
'<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', () => {
|
||||
assertCodegen(
|
||||
`<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')])}`]
|
||||
)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user