From b5f1f054375e7fb722e0bf92b915f038b63a9db9 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 21 Nov 2017 13:14:19 +0100 Subject: [PATCH 1/2] fix(warn): do not warn when destructuring in v-for Fixes #7096 --- src/compiler/error-detector.js | 6 +++++- test/unit/features/options/template.spec.js | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/compiler/error-detector.js b/src/compiler/error-detector.js index 094ec99aa29..4468b8e7700 100644 --- a/src/compiler/error-detector.js +++ b/src/compiler/error-detector.js @@ -80,7 +80,11 @@ function checkIdentifier ( ) { if (typeof ident === 'string') { try { - new Function(`var ${ident}`) + // #7096 use an array because it makes it possible to destructure + // arrays and objects: + // var { foo } = [] works + // var [ foo ] = [] works + new Function(`var ${ident} = []`) } catch (e) { errors.push(`invalid ${type} "${ident}" in expression: ${text.trim()}`) } diff --git a/test/unit/features/options/template.spec.js b/test/unit/features/options/template.spec.js index 09aafd3efaa..831bdd85711 100644 --- a/test/unit/features/options/template.spec.js +++ b/test/unit/features/options/template.spec.js @@ -78,6 +78,25 @@ describe('Options template', () => { expect('Raw expression: v-for="(1, 2) in a----"').toHaveBeenWarned() }) + // #7096 + it('should not warn with object destructuring in v-for', () => { + new Vue({ + data: { items: [] }, + template: '
' + }).$mount() + expect('Error compiling template').not.toHaveBeenWarned() + expect('invalid v-for alias ').not.toHaveBeenWarned() + }) + + it('should not warn with array destructuring in v-for', () => { + new Vue({ + data: { items: [] }, + template: '
' + }).$mount() + expect('Error compiling template').not.toHaveBeenWarned() + expect('invalid v-for alias ').not.toHaveBeenWarned() + }) + it('warn error in generated function (v-on)', () => { new Vue({ template: `
`, From 460e477cdfec84dba944717cc5129ad44ad7a6a2 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 21 Nov 2017 13:29:37 +0100 Subject: [PATCH 2/2] test: skip tests that cannot be run yet PhantomJS does not support the destructuring syntax and therefore do not make the tests pass. Using ChromeHeadless works but break 6 transition tests. Regular Chrome works fine. --- test/unit/features/options/template.spec.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/unit/features/options/template.spec.js b/test/unit/features/options/template.spec.js index 831bdd85711..bbc2a4038cf 100644 --- a/test/unit/features/options/template.spec.js +++ b/test/unit/features/options/template.spec.js @@ -79,7 +79,8 @@ describe('Options template', () => { }) // #7096 - it('should not warn with object destructuring in v-for', () => { + // TODO activate once we use something newer than PhantomJS + xit('should not warn with object destructuring in v-for', () => { new Vue({ data: { items: [] }, template: '
' @@ -88,7 +89,7 @@ describe('Options template', () => { expect('invalid v-for alias ').not.toHaveBeenWarned() }) - it('should not warn with array destructuring in v-for', () => { + xit('should not warn with array destructuring in v-for', () => { new Vue({ data: { items: [] }, template: '
'