fix: fix v-for alias deconstruct regression

fix #7096
This commit is contained in:
Evan You 2017-11-21 09:06:19 -05:00
parent f9f74231a2
commit ebcef58645
2 changed files with 19 additions and 2 deletions

View File

@ -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()}`)
}

View File

@ -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: '<div><div v-for="({ foo }, i) in list">{{ foo }}{{ i }}</div></div>'
}).$mount()
expect(vm.$el.textContent).toBe('hi0')
})
}
})