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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: cache jest fn call parsing results #1187

Merged
merged 2 commits into from Aug 15, 2022
Merged
Changes from 1 commit
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
17 changes: 17 additions & 0 deletions src/rules/utils/parseJestFnCall.ts
Expand Up @@ -181,6 +181,8 @@ const resolvePossibleAliasedGlobal = (
return null;
};

const parseJestFnCallCache = new WeakMap();

export const parseJestFnCall = (
node: TSESTree.CallExpression,
context: TSESLint.RuleContext<string, unknown[]>,
Expand All @@ -197,6 +199,21 @@ export const parseJestFnCall = (
export const parseJestFnCallWithReason = (
node: TSESTree.CallExpression,
context: TSESLint.RuleContext<string, unknown[]>,
): ParsedJestFnCall | string | null => {
if (parseJestFnCallCache.has(node)) {
return parseJestFnCallCache.get(node);
}

const parsedJestFnCall = parseJestFnCallWithReasonInner(node, context);
G-Rath marked this conversation as resolved.
Show resolved Hide resolved

parseJestFnCallCache.set(node, parsedJestFnCall);

return parsedJestFnCall;
};

const parseJestFnCallWithReasonInner = (
node: TSESTree.CallExpression,
context: TSESLint.RuleContext<string, unknown[]>,
): ParsedJestFnCall | string | null => {
const chain = getNodeChain(node);

Expand Down