diff --git a/src/compiler/error-detector.js b/src/compiler/error-detector.js index 094ec99aa29..e729c499a33 100644 --- a/src/compiler/error-detector.js +++ b/src/compiler/error-detector.js @@ -80,7 +80,7 @@ function checkIdentifier ( ) { if (typeof ident === 'string') { try { - new Function(`var ${ident}`) + new Function(`var ${ident}=_`) } catch (e) { errors.push(`invalid ${type} "${ident}" in expression: ${text.trim()}`) } diff --git a/test/unit/features/directives/for.spec.js b/test/unit/features/directives/for.spec.js index db92426b2d1..89a026e915a 100644 --- a/test/unit/features/directives/for.spec.js +++ b/test/unit/features/directives/for.spec.js @@ -446,7 +446,7 @@ describe('Directive v-for', () => { }).then(done) }) - it('strings', done => { + it('should work with strings', done => { const vm = new Vue({ data: { text: 'foo' @@ -463,4 +463,21 @@ describe('Directive v-for', () => { expect(vm.$el.textContent).toMatch('f.o.o.b.a.r.') }).then(done) }) + + const supportsDeconstruct = (() => { + try { + new Function('var { foo } = bar') + return true + } catch (e) {} + })() + + if (supportsDeconstruct) { + it('should support deconstruct syntax in alias position', () => { + const vm = new Vue({ + data: { list: [{ foo: 'hi' }] }, + template: '
{{ foo }}{{ i }}
' + }).$mount() + expect(vm.$el.textContent).toBe('hi0') + }) + } })