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..bbc2a4038cf 100644 --- a/test/unit/features/options/template.spec.js +++ b/test/unit/features/options/template.spec.js @@ -78,6 +78,26 @@ describe('Options template', () => { expect('Raw expression: v-for="(1, 2) in a----"').toHaveBeenWarned() }) + // #7096 + // TODO activate once we use something newer than PhantomJS + xit('should not warn with object destructuring in v-for', () => { + new Vue({ + data: { items: [] }, + template: '