Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: prefer-destructuring error with computed properties (fixes #9784) (
  • Loading branch information
not-an-aardvark committed Jan 10, 2018
1 parent 601f851 commit 6a5cd32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/rules/prefer-destructuring.js
Expand Up @@ -165,8 +165,10 @@ module.exports = {
if (shouldCheck(reportNode.type, "object")) {
const property = rightNode.property;

if ((property.type === "Literal" && leftNode.name === property.value) || (property.type === "Identifier" &&
leftNode.name === property.name)) {
if (
(property.type === "Literal" && leftNode.name === property.value) ||
(property.type === "Identifier" && leftNode.name === property.name && !rightNode.computed)
) {
report(reportNode, "object");
}
}
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/rules/prefer-destructuring.js
Expand Up @@ -131,7 +131,9 @@ ruleTester.run("prefer-destructuring", rule, {
code: "var foo = object.foo;",
options: [{ VariableDeclarator: { object: false }, AssignmentExpression: { object: true } }]
},
"class Foo extends Bar { static foo() {var foo = super.foo} }"
"class Foo extends Bar { static foo() {var foo = super.foo} }",
"foo = bar[foo];",
"var foo = bar[foo];"
],

invalid: [
Expand Down

0 comments on commit 6a5cd32

Please sign in to comment.