File tree 2 files changed +24
-1
lines changed
test/unit/features/options
2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,11 @@ function checkIdentifier (
80
80
) {
81
81
if ( typeof ident === 'string' ) {
82
82
try {
83
- new Function ( `var ${ ident } ` )
83
+ // #7096 use an array because it makes it possible to destructure
84
+ // arrays and objects:
85
+ // var { foo } = [] works
86
+ // var [ foo ] = [] works
87
+ new Function ( `var ${ ident } = []` )
84
88
} catch ( e ) {
85
89
errors . push ( `invalid ${ type } "${ ident } " in expression: ${ text . trim ( ) } ` )
86
90
}
Original file line number Diff line number Diff line change @@ -78,6 +78,25 @@ describe('Options template', () => {
78
78
expect ( 'Raw expression: v-for="(1, 2) in a----"' ) . toHaveBeenWarned ( )
79
79
} )
80
80
81
+ // #7096
82
+ it ( 'should not warn with object destructuring in v-for' , ( ) => {
83
+ new Vue ( {
84
+ data : { items : [ ] } ,
85
+ template : '<div><div v-for="{ foo } in items"></div></div>'
86
+ } ) . $mount ( )
87
+ expect ( 'Error compiling template' ) . not . toHaveBeenWarned ( )
88
+ expect ( 'invalid v-for alias ' ) . not . toHaveBeenWarned ( )
89
+ } )
90
+
91
+ it ( 'should not warn with array destructuring in v-for' , ( ) => {
92
+ new Vue ( {
93
+ data : { items : [ ] } ,
94
+ template : '<div><div v-for="[ foo ] in items"></div></div>'
95
+ } ) . $mount ( )
96
+ expect ( 'Error compiling template' ) . not . toHaveBeenWarned ( )
97
+ expect ( 'invalid v-for alias ' ) . not . toHaveBeenWarned ( )
98
+ } )
99
+
81
100
it ( 'warn error in generated function (v-on)' , ( ) => {
82
101
new Vue ( {
83
102
template : `<div @click="delete('Delete')"></div>` ,
You can’t perform that action at this time.
0 commit comments