Skip to content

Commit

Permalink
Cache getSourceFileOfNode within the checker
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham committed Jul 13, 2022
1 parent 6f0edcc commit ef3813c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,17 @@ namespace ts {

return checker;

function getSourceFileOfNode(node: Node): SourceFile;
function getSourceFileOfNode(node: Node | undefined): SourceFile | undefined;
function getSourceFileOfNode(node: Node | undefined) {
if (!node) return node;
const links = getNodeLinks(node);
if (!hasProperty(links, "sourceFile")) {
links.sourceFile = ts.getSourceFileOfNode(node);
}
return links.sourceFile;
}

function getCachedType(key: string | undefined) {
return key ? cachedTypes.get(key) : undefined;
}
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5337,6 +5337,7 @@ namespace ts {
skipDirectInference?: true; // Flag set by the API `getContextualType` call on a node when `Completions` is passed to force the checker to skip making inferences to a node's type
declarationRequiresScopeChange?: boolean; // Set by `useOuterVariableScopeInParameter` in checker when downlevel emit would change the name resolution scope inside of a parameter.
serializedTypes?: ESMap<string, TypeNode & {truncating?: boolean, addedLength: number}>; // Collection of types serialized at this location
sourceFile?: SourceFile | undefined; // Cached lookup result of `getSourceFileOfNode`
}

export const enum TypeFlags {
Expand Down

0 comments on commit ef3813c

Please sign in to comment.