From a1ae6e2cfb2ddef39af78509a3e95d72e48d1997 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Mon, 22 Jul 2019 14:47:17 -0700 Subject: [PATCH] Clean up memoization when done --- src/compiler/core.ts | 11 ++++++++--- src/compiler/moduleSpecifiers.ts | 4 ++++ src/services/codefixes/importFixes.ts | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 6e3d92bc08d..fe174ea06a0 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1634,10 +1634,16 @@ namespace ts { }; } - export function memoizeOne(callback: (...args: ArgsT) => ReturnT) { + export function memoizeOne(callback: (...args: ArgsT) => ReturnT): typeof callback & { clear: () => void } { let value: ReturnT; let cachedArgs: ArgsT; - return (...args: ArgsT) => { + runMemoized.clear = () => { + value = undefined!; + cachedArgs = undefined!; + }; + return runMemoized; + + function runMemoized(...args: ArgsT) { const length = args.length; if (cachedArgs && cachedArgs.length === length) { for (let i = 0; i < length; i++) { @@ -1653,7 +1659,6 @@ namespace ts { }; } - /** * High-order function, composes functions. Note that functions are composed inside-out; * for example, `compose(a, b)` is the equivalent of `x => b(a(x))`. diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index 76b33ab13cc..d72e58587f5 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -185,6 +185,10 @@ namespace ts.moduleSpecifiers { return result; }); + export function clearSymlinksCache() { + discoverProbableSymlinks.clear(); + } + /** * Looks for existing imports that use symlinks to this module. * Symlinks will be returned first so they are preferred over the real path. diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index eacf39a2784..95d3bf01aec 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -594,6 +594,7 @@ namespace ts.codefix { } } }); + moduleSpecifiers.clearSymlinksCache(); function getNodeModulesPackageNameFromFileName(importedFileName: string): string | undefined { if (!stringContains(importedFileName, "node_modules")) {