Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(eslint-plugin): [explicit-module-boundary-types] cyclical referen…
…ce infinite recursion crash (#2482)

Co-authored-by: Tadhg McDonald-Jensen <tadhg.mcdonaldjensen@carleton.ca>
  • Loading branch information
tadhgmister and Tadhg McDonald-Jensen committed Sep 6, 2020
1 parent 3d07a99 commit 8693653
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Expand Up @@ -96,6 +96,10 @@ export default util.createRule<Options, MessageIds>({
// tracks functions that were found whilst traversing
const foundFunctions: FunctionNode[] = [];

// all nodes visited, avoids infinite recursion for cyclic references
// (such as class member referring to itself)
const alreadyVisited = new Set<TSESTree.Node>();

/*
# How the rule works:
Expand Down Expand Up @@ -311,9 +315,10 @@ export default util.createRule<Options, MessageIds>({
}

function checkNode(node: TSESTree.Node | null): void {
if (node == null) {
if (node == null || alreadyVisited.has(node)) {
return;
}
alreadyVisited.add(node);

switch (node.type) {
case AST_NODE_TYPES.ArrowFunctionExpression:
Expand Down
Expand Up @@ -654,6 +654,11 @@ export abstract class Foo<T> {
`
export declare class Foo {
set time(seconds: number);
}
`,
`
export class A {
b = A;
}
`,
],
Expand Down

0 comments on commit 8693653

Please sign in to comment.