Skip to content

Commit

Permalink
perf: skip normalization on single child element v-for
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 11, 2018
1 parent 4748760 commit 4074104
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions test/unit/modules/compiler/codegen.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)}`
)
})

Expand Down Expand Up @@ -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')])}`]
)
})
Expand Down

0 comments on commit 4074104

Please sign in to comment.