Skip to content

Commit 3c0af8a

Browse files
authored
fix: crash on for statement in *-prototype-* rules (#224)
1 parent 561e75b commit 3c0af8a

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

lib/util/define-nonstandard-prototype-properties-handler/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ function defineNonstandardPrototypePropertiesHandler(
9393
assignmentNode.type === "VariableDeclarator"
9494
? assignmentNode.init
9595
: assignmentNode.right
96+
if (!objectNode) {
97+
return
98+
}
9699

97100
for (const className of classNames) {
98101
if (!objectTypeChecker(node, objectNode, className)) {

lib/util/define-prototype-method-handler/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ function definePrototypeMethodHandler(context, nameMap, options) {
104104
assignmentNode.type === "VariableDeclarator"
105105
? assignmentNode.init
106106
: assignmentNode.right
107+
if (!objectNode) {
108+
return
109+
}
107110
let objectTypeResult = undefined
108111
if (
109112
methodNames.includes(propertyName) &&
@@ -163,6 +166,9 @@ function definePrototypeMethodHandler(context, nameMap, options) {
163166
assignmentNode.type === "VariableDeclarator"
164167
? assignmentNode.init
165168
: assignmentNode.right
169+
if (!objectNode) {
170+
return
171+
}
166172
for (const [className, methodNames] of nameMapEntries) {
167173
let objectTypeResult = undefined
168174
if (

tests/lib/rules/no-array-prototype-at.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ new RuleTester().run(ruleId, rule, {
2121
options: [{ aggressive: false }],
2222
settings: { "es-x": { aggressive: true } },
2323
},
24+
// Test for https://github.com/eslint-community/eslint-plugin-es-x/issues/223
25+
"for (const { x } of foo) {}",
2426
],
2527
invalid: [
2628
{

tests/lib/rules/no-nonstandard-array-prototype-properties.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ new RuleTester().run(ruleId, rule, {
1717
"['A'][0]",
1818
"['A']['0']",
1919
{ code: "['A'].unknown()", options: [{ allow: ["unknown"] }] },
20+
// Test for https://github.com/eslint-community/eslint-plugin-es-x/issues/223
21+
"for (const { x } of foo) {}",
2022
],
2123
invalid: [
2224
{

0 commit comments

Comments
 (0)