Skip to content

Commit 4ef4cb0

Browse files
committed
Use value of object pattern instead of key for assignment checking. (close #26)
1 parent 4036438 commit 4ef4cb0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/rules/no-reassign.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ module.exports = function (context) {
6666
// todo: destructuring assignment
6767
'ObjectPattern': function (o) {
6868
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)
7072
})
7173
},
7274

tests/lib/rules/no-reassign.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ eslintTester.addRuleTest('lib/rules/no-reassign', {
2424
, ecmaFeatures: { destructuring: true } })
2525
, test({ code: 'var [, y] = ["foo", 42];'
2626
, 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 } })
2731
],
2832

2933
invalid: [
@@ -78,6 +82,11 @@ eslintTester.addRuleTest('lib/rules/no-reassign', {
7882
errors: [{ message: 'Reassignment of local imported name \'foo\'.'}],
7983
ecmaFeatures: {modules: true, destructuring: true}}),
8084

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+
8190
test({
8291
code: 'import { foo } from \'./bar\'; var [foo] = [\'y\'];',
8392
errors: [{ message: 'Reassignment of local imported name \'foo\'.'}],

0 commit comments

Comments
 (0)