Skip to content

Commit 71b4b25

Browse files
committed
fix: allow multiline expression in v-for
fix #7792
1 parent af5453c commit 71b4b25

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/compiler/parser/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121

2222
export const onRE = /^@|^v-on:/
2323
export const dirRE = /^v-|^@|^:/
24-
export const forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/
24+
export const forAliasRE = /([^]*?)\s+(?:in|of)\s+([^]*)/
2525
export const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/
2626
const stripParensRE = /^\(|\)$/g
2727

test/unit/features/directives/for.spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,26 @@ describe('Directive v-for', () => {
464464
}).then(done)
465465
})
466466

467+
// #7792
468+
it('should work with multiline expressions', () => {
469+
const vm = new Vue({
470+
data: {
471+
a: [1],
472+
b: [2]
473+
},
474+
template: `
475+
<div>
476+
<span v-for="n in (
477+
a.concat(
478+
b
479+
)
480+
)">{{ n }}</span>
481+
</div>
482+
`
483+
}).$mount()
484+
expect(vm.$el.textContent).toBe('12')
485+
})
486+
467487
const supportsDestructuring = (() => {
468488
try {
469489
new Function('var { foo } = bar')

0 commit comments

Comments
 (0)