Skip to content

Memoize collecting set of all imported packages #26263

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Aug 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ namespace ts {
}

export function createTypeChecker(host: TypeCheckerHost, produceDiagnostics: boolean): TypeChecker {
const getPackagesSet: () => Map<true> = memoize(() => {
const set = createMap<true>();
host.getSourceFiles().forEach(sf => {
if (!sf.resolvedModules) return;

forEachEntry(sf.resolvedModules, r => {
if (r && r.packageId) set.set(r.packageId.name, true);
});
});
return set;
});

// Cancellation that controls whether or not we can cancel in the middle of type checking.
// In general cancelling is *not* safe for the type checker. We might be in the middle of
// computing something, and we will leave our internals in an inconsistent state. Callers
Expand Down Expand Up @@ -2259,8 +2271,7 @@ namespace ts {
resolvedFileName));
}
function typesPackageExists(packageName: string): boolean {
return host.getSourceFiles().some(sf => !!sf.resolvedModules && !!forEachEntry(sf.resolvedModules, r =>
r && r.packageId && r.packageId.name === getTypesPackageName(packageName)));
return getPackagesSet().has(getTypesPackageName(packageName));
}

// An external module with an 'export =' declaration resolves to the target of the 'export =' declaration,
Expand Down