Skip to content

Commit

Permalink
fix: crash on for statement in *-prototype-* rules (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Nov 18, 2024
1 parent 561e75b commit 3c0af8a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ function defineNonstandardPrototypePropertiesHandler(
assignmentNode.type === "VariableDeclarator"
? assignmentNode.init
: assignmentNode.right
if (!objectNode) {
return
}

for (const className of classNames) {
if (!objectTypeChecker(node, objectNode, className)) {
Expand Down
6 changes: 6 additions & 0 deletions lib/util/define-prototype-method-handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ function definePrototypeMethodHandler(context, nameMap, options) {
assignmentNode.type === "VariableDeclarator"
? assignmentNode.init
: assignmentNode.right
if (!objectNode) {
return
}
let objectTypeResult = undefined
if (
methodNames.includes(propertyName) &&
Expand Down Expand Up @@ -163,6 +166,9 @@ function definePrototypeMethodHandler(context, nameMap, options) {
assignmentNode.type === "VariableDeclarator"
? assignmentNode.init
: assignmentNode.right
if (!objectNode) {
return
}
for (const [className, methodNames] of nameMapEntries) {
let objectTypeResult = undefined
if (
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/no-array-prototype-at.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ new RuleTester().run(ruleId, rule, {
options: [{ aggressive: false }],
settings: { "es-x": { aggressive: true } },
},
// Test for https://github.com/eslint-community/eslint-plugin-es-x/issues/223
"for (const { x } of foo) {}",
],
invalid: [
{
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/no-nonstandard-array-prototype-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ new RuleTester().run(ruleId, rule, {
"['A'][0]",
"['A']['0']",
{ code: "['A'].unknown()", options: [{ allow: ["unknown"] }] },
// Test for https://github.com/eslint-community/eslint-plugin-es-x/issues/223
"for (const { x } of foo) {}",
],
invalid: [
{
Expand Down

0 comments on commit 3c0af8a

Please sign in to comment.