Skip to content

Commit

Permalink
perf: cache jest fn call parsing results (#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored Aug 15, 2022
1 parent c204087 commit 525631e
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/rules/utils/parseJestFnCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ const resolvePossibleAliasedGlobal = (
return null;
};

const parseJestFnCallCache = new WeakMap<
TSESTree.CallExpression,
ParsedJestFnCall | string | null
>();

export const parseJestFnCall = (
node: TSESTree.CallExpression,
context: TSESLint.RuleContext<string, unknown[]>,
Expand All @@ -197,6 +202,23 @@ export const parseJestFnCall = (
export const parseJestFnCallWithReason = (
node: TSESTree.CallExpression,
context: TSESLint.RuleContext<string, unknown[]>,
): ParsedJestFnCall | string | null => {
let parsedJestFnCall = parseJestFnCallCache.get(node);

if (parsedJestFnCall) {
return parsedJestFnCall;
}

parsedJestFnCall = parseJestFnCallWithReasonInner(node, context);

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

0 comments on commit 525631e

Please sign in to comment.