فهرست منبع

perf: skip normalization on single child element v-for

Evan You 7 سال پیش
والد
کامیت
4074104fac
2فایلهای تغییر یافته به همراه10 افزوده شده و 8 حذف شده
  1. 3 1
      src/compiler/codegen/index.js
  2. 7 7
      test/unit/modules/compiler/codegen.spec.js

+ 3 - 1
src/compiler/codegen/index.js

@@ -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

+ 7 - 7
test/unit/modules/compiler/codegen.spec.js

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