Skip to content

Commit

Permalink
Fix computed key case
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Nov 27, 2023
1 parent a7c0739 commit 604a3d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions eslint/babel-eslint-plugin/src/rules/no-undef.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ const rule = new eslint.Linter().getRules().get("no-undef");
* @param {ASTNode} node CallExpression node
* @returns {Boolean} Returns true if the node is under a decorator.
*/
function isAccessorField(node) {
function isAccessorFieldName(node) {
return (
node.parent.type === "ClassAccessorProperty" && node.parent.key === node
node.parent.type === "ClassAccessorProperty" &&
node.parent.key === node &&
!node.parent.computed
);
}

module.exports = ruleComposer.filterReports(
rule,
problem => !isAccessorField(problem.node),
problem => !isAccessorFieldName(problem.node),
);
4 changes: 4 additions & 0 deletions eslint/babel-eslint-plugin/test/rules/no-undef.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ ruleTester.run("@babel/no-undef", rule, {
code: "{ using x = 2; } x;",
errors: [{ message: "'x' is not defined." }],
},
{
code: "class MyClass { accessor [x] = 2 }",
errors: [{ message: "'x' is not defined." }],
},
],
});

0 comments on commit 604a3d6

Please sign in to comment.