From 8e4d75affb86d89513a0df7cff50a7b3f5285568 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 11 Mar 2018 11:51:51 -0400 Subject: [PATCH] fix: allow multiline expression in v-for fix #7792 --- src/compiler/parser/index.js | 2 +- test/unit/features/directives/for.spec.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/compiler/parser/index.js b/src/compiler/parser/index.js index ba1b726870a..a603b36bb55 100644 --- a/src/compiler/parser/index.js +++ b/src/compiler/parser/index.js @@ -21,7 +21,7 @@ import { export const onRE = /^@|^v-on:/ export const dirRE = /^v-|^@|^:/ -export const forAliasRE = /(.*?)\s+(?:in|of)\s+(.*)/ +export const forAliasRE = /([^]*?)\s+(?:in|of)\s+([^]*)/ export const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/ const stripParensRE = /^\(|\)$/g diff --git a/test/unit/features/directives/for.spec.js b/test/unit/features/directives/for.spec.js index ec270ca9cc2..22528be62fc 100644 --- a/test/unit/features/directives/for.spec.js +++ b/test/unit/features/directives/for.spec.js @@ -464,6 +464,26 @@ describe('Directive v-for', () => { }).then(done) }) + // #7792 + it('should work with multiline expressions', () => { + const vm = new Vue({ + data: { + a: [1], + b: [2] + }, + template: ` +
+ {{ n }} +
+ ` + }).$mount() + expect(vm.$el.textContent).toBe('12') + }) + const supportsDestructuring = (() => { try { new Function('var { foo } = bar')