Skip to content

Commit

Permalink
fix: fix v-for alias deconstruct regression
Browse files Browse the repository at this point in the history
fix #7096
  • Loading branch information
yyx990803 committed Nov 21, 2017
1 parent f9f7423 commit ebcef58
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compiler/error-detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`)
}
Expand Down
19 changes: 18 additions & 1 deletion test/unit/features/directives/for.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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')
})
}
})

0 comments on commit ebcef58

Please sign in to comment.