Просмотр исходного кода

support destructuring in v-for alias

Evan You 9 лет назад
Родитель
Сommit
a0d8603f90
2 измененных файлов с 10 добавлено и 1 удалено
  1. 1 1
      src/compiler/parser/index.js
  2. 9 0
      test/unit/modules/compiler/codegen.spec.js

+ 1 - 1
src/compiler/parser/index.js

@@ -19,7 +19,7 @@ import {
 
 export const dirRE = /^v-|^@|^:/
 export const forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/
-export const forIteratorRE = /\(([^,]*),([^,]*)(?:,([^,]*))?\)/
+export const forIteratorRE = /\((\{[^}]*\}|[^,]*),([^,]*)(?:,([^,]*))?\)/
 const bindRE = /^:|^v-bind:/
 const onRE = /^@|^v-on:/
 const argRE = /:(.*)$/

+ 9 - 0
test/unit/modules/compiler/codegen.spec.js

@@ -58,6 +58,15 @@ describe('codegen', () => {
       '<li v-for="(item, key, index) in items"></li>',
       `with(this){return _l((items),function(item,key,index){return _h('li')})}`
     )
+    // destructuring
+    assertCodegen(
+      '<li v-for="{ a, b } in items"></li>',
+      `with(this){return _l((items),function({ a, b }){return _h('li')})}`
+    )
+    assertCodegen(
+      '<li v-for="({ a, b }, key, index) in items"></li>',
+      `with(this){return _l((items),function({ a, b },key,index){return _h('li')})}`
+    )
   })
 
   it('generate v-if directive', () => {