Skip to content

Commit ef3813c

Browse files
committed
Cache getSourceFileOfNode within the checker
1 parent 6f0edcc commit ef3813c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/compiler/checker.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,17 @@ namespace ts {
10751075

10761076
return checker;
10771077

1078+
function getSourceFileOfNode(node: Node): SourceFile;
1079+
function getSourceFileOfNode(node: Node | undefined): SourceFile | undefined;
1080+
function getSourceFileOfNode(node: Node | undefined) {
1081+
if (!node) return node;
1082+
const links = getNodeLinks(node);
1083+
if (!hasProperty(links, "sourceFile")) {
1084+
links.sourceFile = ts.getSourceFileOfNode(node);
1085+
}
1086+
return links.sourceFile;
1087+
}
1088+
10781089
function getCachedType(key: string | undefined) {
10791090
return key ? cachedTypes.get(key) : undefined;
10801091
}

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5337,6 +5337,7 @@ namespace ts {
53375337
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
53385338
declarationRequiresScopeChange?: boolean; // Set by `useOuterVariableScopeInParameter` in checker when downlevel emit would change the name resolution scope inside of a parameter.
53395339
serializedTypes?: ESMap<string, TypeNode & {truncating?: boolean, addedLength: number}>; // Collection of types serialized at this location
5340+
sourceFile?: SourceFile | undefined; // Cached lookup result of `getSourceFileOfNode`
53405341
}
53415342

53425343
export const enum TypeFlags {

0 commit comments

Comments
 (0)