Clean up memoization when done

This commit is contained in:
Andrew Branch
2019-07-29 10:21:35 -07:00
parent f953b4d737
commit a1ae6e2cfb
3 changed files with 13 additions and 3 deletions
+8 -3
View File
@@ -1634,10 +1634,16 @@ namespace ts {
};
}
export function memoizeOne<ArgsT extends unknown[], ReturnT>(callback: (...args: ArgsT) => ReturnT) {
export function memoizeOne<ArgsT extends unknown[], ReturnT>(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))`.
+4
View File
@@ -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.
+1
View File
@@ -594,6 +594,7 @@ namespace ts.codefix {
}
}
});
moduleSpecifiers.clearSymlinksCache();
function getNodeModulesPackageNameFromFileName(importedFileName: string): string | undefined {
if (!stringContains(importedFileName, "node_modules")) {