Skip to content

Commit 8693653

Browse files
tadhgmisterTadhg McDonald-Jensen
and
Tadhg McDonald-Jensen
authored
fix(eslint-plugin): [explicit-module-boundary-types] cyclical reference infinite recursion crash (#2482)
Co-authored-by: Tadhg McDonald-Jensen <[email protected]>
1 parent 3d07a99 commit 8693653

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Diff for: packages/eslint-plugin/src/rules/explicit-module-boundary-types.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ export default util.createRule<Options, MessageIds>({
9696
// tracks functions that were found whilst traversing
9797
const foundFunctions: FunctionNode[] = [];
9898

99+
// all nodes visited, avoids infinite recursion for cyclic references
100+
// (such as class member referring to itself)
101+
const alreadyVisited = new Set<TSESTree.Node>();
102+
99103
/*
100104
# How the rule works:
101105
@@ -311,9 +315,10 @@ export default util.createRule<Options, MessageIds>({
311315
}
312316

313317
function checkNode(node: TSESTree.Node | null): void {
314-
if (node == null) {
318+
if (node == null || alreadyVisited.has(node)) {
315319
return;
316320
}
321+
alreadyVisited.add(node);
317322

318323
switch (node.type) {
319324
case AST_NODE_TYPES.ArrowFunctionExpression:

Diff for: packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,11 @@ export abstract class Foo<T> {
654654
`
655655
export declare class Foo {
656656
set time(seconds: number);
657+
}
658+
`,
659+
`
660+
export class A {
661+
b = A;
657662
}
658663
`,
659664
],

0 commit comments

Comments
 (0)