Skip to content

Commit

Permalink
fix(eslint-plugin): [no-invalid-this] crash when used with eslint 8.7…
Browse files Browse the repository at this point in the history
….0 (#4448)

* fix(eslint-plugin): [no-invalid-this] crash when used with eslint 8.7.0

* revert eslint version
  • Loading branch information
ota-meshi committed Jan 17, 2022
1 parent ba3d3a3 commit e56f1e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/eslint-plugin/src/rules/no-invalid-this.ts
Expand Up @@ -64,12 +64,12 @@ export default createRule<Options, MessageIds>({
),
);
// baseRule's work
rules.FunctionDeclaration(node);
rules.FunctionDeclaration?.(node);
},
'FunctionDeclaration:exit'(node: TSESTree.FunctionDeclaration): void {
thisIsValidStack.pop();
// baseRule's work
rules['FunctionDeclaration:exit'](node);
rules['FunctionDeclaration:exit']?.(node);
},
FunctionExpression(node: TSESTree.FunctionExpression): void {
thisIsValidStack.push(
Expand All @@ -79,12 +79,12 @@ export default createRule<Options, MessageIds>({
),
);
// baseRule's work
rules.FunctionExpression(node);
rules.FunctionExpression?.(node);
},
'FunctionExpression:exit'(node: TSESTree.FunctionExpression): void {
thisIsValidStack.pop();
// baseRule's work
rules['FunctionExpression:exit'](node);
rules['FunctionExpression:exit']?.(node);
},
ThisExpression(node: TSESTree.ThisExpression): void {
const thisIsValidHere = thisIsValidStack[thisIsValidStack.length - 1];
Expand Down
20 changes: 14 additions & 6 deletions packages/eslint-plugin/typings/eslint-rules.d.ts
Expand Up @@ -701,12 +701,20 @@ declare module 'eslint/lib/rules/no-invalid-this' {
}?,
],
{
Program(node: TSESTree.Program): void;
'Program:exit'(node: TSESTree.Program): void;
FunctionDeclaration(node: TSESTree.FunctionDeclaration): void;
'FunctionDeclaration:exit'(node: TSESTree.FunctionDeclaration): void;
FunctionExpression(node: TSESTree.FunctionExpression): void;
'FunctionExpression:exit'(node: TSESTree.FunctionExpression): void;
// for ESLint < v8.7.0
Program?: (node: TSESTree.Program) => void;
'Program:exit'?: (node: TSESTree.Program) => void;
FunctionDeclaration?: (node: TSESTree.FunctionDeclaration) => void;
'FunctionDeclaration:exit'?: (node: TSESTree.FunctionDeclaration) => void;
FunctionExpression?: (node: TSESTree.FunctionExpression) => void;
'FunctionExpression:exit'?: (node: TSESTree.FunctionExpression) => void;

// for ESLint >= v8.7.0
// We don't use it and we don't have the CodePath types, so comment out it.
// onCodePathStart?: (codePath: unknown, node: TSESTree.Node) => void
// onCodePathEnd?: (codePath: unknown, node: TSESTree.Node) => void

// Common
ThisExpression(node: TSESTree.ThisExpression): void;
}
>;
Expand Down

0 comments on commit e56f1e5

Please sign in to comment.