Skip to content

Commit

Permalink
refactor: only ever handle one node per iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Mar 30, 2021
1 parent be72c43 commit cee1fb1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 4 additions & 6 deletions packages/eslint-plugin/src/util/getThisExpression.ts
Expand Up @@ -9,14 +9,12 @@ export function getThisExpression(
while (node) {
if (node.type === AST_NODE_TYPES.CallExpression) {
node = node.callee;
}

if (node.type === AST_NODE_TYPES.ThisExpression) {
} else if (node.type === AST_NODE_TYPES.ThisExpression) {
return node;
}

if ('object' in node) {
} else if (node.type === AST_NODE_TYPES.MemberExpression) {
node = node.object;
} else if (node.type === AST_NODE_TYPES.ChainExpression) {
node = node.expression;
} else {
break;
}
Expand Down
Expand Up @@ -215,6 +215,9 @@ const methods = {
methodC() {
return true
},
methodD() {
return (this?.methodA)?.()
}
};
`,
errors: [
Expand All @@ -230,6 +233,12 @@ const methods = {
column: 12,
endColumn: 31,
},
{
messageId: 'unsafeThisMemberExpression',
line: 14,
column: 13,
endColumn: 26,
},
],
},
],
Expand Down

0 comments on commit cee1fb1

Please sign in to comment.