Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reuse circular map #1594

Draft
wants to merge 2 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion factory/parser.ts
Expand Up @@ -58,6 +58,7 @@ import { UnknownTypeNodeParser } from "../src/NodeParser/UnknownTypeNodeParser";
import { VoidTypeNodeParser } from "../src/NodeParser/VoidTypeNodeParser";
import { SubNodeParser } from "../src/SubNodeParser";
import { TopRefNodeParser } from "../src/TopRefNodeParser";
import { BaseType } from "../src/Type/BaseType";

export type ParserAugmentor = (parser: MutableParser) => void;

Expand All @@ -83,8 +84,11 @@ export function createParser(program: ts.Program, config: Config, augmentor?: Pa
return nodeParser;
}
}

const circular: Map<string, BaseType> = new Map();

function withCircular(nodeParser: SubNodeParser): SubNodeParser {
return new CircularReferenceNodeParser(nodeParser);
return new CircularReferenceNodeParser(nodeParser, circular);
}

if (augmentor) {
Expand Down
7 changes: 4 additions & 3 deletions src/CircularReferenceNodeParser.ts
Expand Up @@ -6,9 +6,10 @@ import { ReferenceType } from "./Type/ReferenceType";
import { getKey } from "./Utils/nodeKey";

export class CircularReferenceNodeParser implements SubNodeParser {
protected circular: Map<string, BaseType> = new Map();

public constructor(protected childNodeParser: SubNodeParser) {}
public constructor(
protected childNodeParser: SubNodeParser,
protected circular: Map<string, BaseType> = new Map()
) {}

public supportsNode(node: ts.Node): boolean {
return this.childNodeParser.supportsNode(node);
Expand Down