Skip to content

Commit a0d8603

Browse files
committed
support destructuring in v-for alias
1 parent 662586b commit a0d8603

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/compiler/parser/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919

2020
export const dirRE = /^v-|^@|^:/
2121
export const forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/
22-
export const forIteratorRE = /\(([^,]*),([^,]*)(?:,([^,]*))?\)/
22+
export const forIteratorRE = /\((\{[^}]*\}|[^,]*),([^,]*)(?:,([^,]*))?\)/
2323
const bindRE = /^:|^v-bind:/
2424
const onRE = /^@|^v-on:/
2525
const argRE = /:(.*)$/

test/unit/modules/compiler/codegen.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ describe('codegen', () => {
5858
'<li v-for="(item, key, index) in items"></li>',
5959
`with(this){return _l((items),function(item,key,index){return _h('li')})}`
6060
)
61+
// destructuring
62+
assertCodegen(
63+
'<li v-for="{ a, b } in items"></li>',
64+
`with(this){return _l((items),function({ a, b }){return _h('li')})}`
65+
)
66+
assertCodegen(
67+
'<li v-for="({ a, b }, key, index) in items"></li>',
68+
`with(this){return _l((items),function({ a, b },key,index){return _h('li')})}`
69+
)
6170
})
6271

6372
it('generate v-if directive', () => {

0 commit comments

Comments
 (0)