mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Clean up memoization when done
This commit is contained in:
@@ -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))`.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -594,6 +594,7 @@ namespace ts.codefix {
|
||||
}
|
||||
}
|
||||
});
|
||||
moduleSpecifiers.clearSymlinksCache();
|
||||
|
||||
function getNodeModulesPackageNameFromFileName(importedFileName: string): string | undefined {
|
||||
if (!stringContains(importedFileName, "node_modules")) {
|
||||
|
||||
Reference in New Issue
Block a user