Skip to content

Commit ebcef58

Browse files
committed
fix: fix v-for alias deconstruct regression
fix #7096
1 parent f9f7423 commit ebcef58

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/compiler/error-detector.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function checkIdentifier (
8080
) {
8181
if (typeof ident === 'string') {
8282
try {
83-
new Function(`var ${ident}`)
83+
new Function(`var ${ident}=_`)
8484
} catch (e) {
8585
errors.push(`invalid ${type} "${ident}" in expression: ${text.trim()}`)
8686
}

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ describe('Directive v-for', () => {
446446
}).then(done)
447447
})
448448

449-
it('strings', done => {
449+
it('should work with strings', done => {
450450
const vm = new Vue({
451451
data: {
452452
text: 'foo'
@@ -463,4 +463,21 @@ describe('Directive v-for', () => {
463463
expect(vm.$el.textContent).toMatch('f.o.o.b.a.r.')
464464
}).then(done)
465465
})
466+
467+
const supportsDeconstruct = (() => {
468+
try {
469+
new Function('var { foo } = bar')
470+
return true
471+
} catch (e) {}
472+
})()
473+
474+
if (supportsDeconstruct) {
475+
it('should support deconstruct syntax in alias position', () => {
476+
const vm = new Vue({
477+
data: { list: [{ foo: 'hi' }] },
478+
template: '<div><div v-for="({ foo }, i) in list">{{ foo }}{{ i }}</div></div>'
479+
}).$mount()
480+
expect(vm.$el.textContent).toBe('hi0')
481+
})
482+
}
466483
})

0 commit comments

Comments
 (0)