File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,9 @@ module.exports = function (context) {
66
66
// todo: destructuring assignment
67
67
'ObjectPattern' : function ( o ) {
68
68
o . properties . forEach ( function ( p ) {
69
- if ( p . key . type === 'Identifier' ) checkIdentifier ( p . key )
69
+ if ( p . value . type === 'Identifier' ) checkIdentifier ( p . value )
70
+ // apparently in `var { foo }`, this fills the key and value fields
71
+ // else if (p.key.type === 'Identifier') checkIdentifier(p.key)
70
72
} )
71
73
} ,
72
74
Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ eslintTester.addRuleTest('lib/rules/no-reassign', {
24
24
, ecmaFeatures : { destructuring : true } } )
25
25
, test ( { code : 'var [, y] = ["foo", 42];'
26
26
, ecmaFeatures : { destructuring : true } } )
27
+
28
+ // valid destructuring
29
+ , test ( { code : 'import * as foo from \'./bar\'; var { foo: bar } = {foo: 42};'
30
+ , ecmaFeatures : { destructuring : true , modules : true } } )
27
31
] ,
28
32
29
33
invalid : [
@@ -78,6 +82,11 @@ eslintTester.addRuleTest('lib/rules/no-reassign', {
78
82
errors : [ { message : 'Reassignment of local imported name \'foo\'.' } ] ,
79
83
ecmaFeatures : { modules : true , destructuring : true } } ) ,
80
84
85
+ test ( {
86
+ code : 'import { foo } from \'./bar\'; var { bar: foo } = { bar: \'y\' };' ,
87
+ errors : [ { message : 'Reassignment of local imported name \'foo\'.' } ] ,
88
+ ecmaFeatures : { modules : true , destructuring : true } } ) ,
89
+
81
90
test ( {
82
91
code : 'import { foo } from \'./bar\'; var [foo] = [\'y\'];' ,
83
92
errors : [ { message : 'Reassignment of local imported name \'foo\'.' } ] ,
You can’t perform that action at this time.
0 commit comments