Skip to content

fix(warn): do not warn when destructuring in v-for #7097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/compiler/error-detector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`)
}
Expand Down
20 changes: 20 additions & 0 deletions test/unit/features/options/template.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<div><div v-for="{ foo } in items"></div></div>'
}).$mount()
expect('Error compiling template').not.toHaveBeenWarned()
expect('invalid v-for alias ').not.toHaveBeenWarned()
})

xit('should not warn with array destructuring in v-for', () => {
new Vue({
data: { items: [] },
template: '<div><div v-for="[ foo ] in items"></div></div>'
}).$mount()
expect('Error compiling template').not.toHaveBeenWarned()
expect('invalid v-for alias ').not.toHaveBeenWarned()
})

it('warn error in generated function (v-on)', () => {
new Vue({
template: `<div @click="delete('Delete')"></div>`,
Expand Down