Skip to content

Commit

Permalink
Add cache to extractBindingTypes function
Browse files Browse the repository at this point in the history
  • Loading branch information
runem committed Oct 17, 2019
1 parent 213c44c commit 1fea72d
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import { HtmlNodeAttrAssignment, HtmlNodeAttrAssignmentKind } from "../../types/
import { HtmlNodeAttrKind } from "../../types/html-node/html-node-attr-types";
import { getDirective } from "../directive/get-directive";

const cache = new WeakMap<HtmlNodeAttrAssignment, { typeA: SimpleType; typeB: SimpleType }>();

export function extractBindingTypes(assignment: HtmlNodeAttrAssignment, request: LitAnalyzerRequest): { typeA: SimpleType; typeB: SimpleType } {
if (cache.has(assignment)) {
return cache.get(assignment)!;
}

const checker = request.program.getTypeChecker();

// Relax the type we are looking at an expression in javascript files
Expand Down Expand Up @@ -44,7 +50,11 @@ export function extractBindingTypes(assignment: HtmlNodeAttrAssignment, request:
typeB = directive.actualType;
}

return { typeA, typeB };
// Cache the result
const result = { typeA, typeB };
cache.set(assignment, result);

return result;
}

export function inferTypeFromAssignment(assignment: HtmlNodeAttrAssignment, checker: TypeChecker): SimpleType | Type {
Expand Down

0 comments on commit 1fea72d

Please sign in to comment.