Skip to content

Commit 4680b54

Browse files
authored
Clear ExportMapCache on cancellation requested (microsoft#48979)
1 parent f8a09be commit 4680b54

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

src/services/exportInfoMap.ts

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -381,38 +381,45 @@ namespace ts {
381381
host.log?.("getExportInfoMap: cache miss or empty; calculating new results");
382382
const compilerOptions = program.getCompilerOptions();
383383
let moduleCount = 0;
384-
forEachExternalModuleToImportFrom(program, host, /*useAutoImportProvider*/ true, (moduleSymbol, moduleFile, program, isFromPackageJson) => {
385-
if (++moduleCount % 100 === 0) cancellationToken?.throwIfCancellationRequested();
386-
const seenExports = new Map<__String, true>();
387-
const checker = program.getTypeChecker();
388-
const defaultInfo = getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
389-
// Note: I think we shouldn't actually see resolved module symbols here, but weird merges
390-
// can cause it to happen: see 'completionsImport_mergedReExport.ts'
391-
if (defaultInfo && isImportableSymbol(defaultInfo.symbol, checker)) {
392-
cache.add(
393-
importingFile.path,
394-
defaultInfo.symbol,
395-
defaultInfo.exportKind === ExportKind.Default ? InternalSymbolName.Default : InternalSymbolName.ExportEquals,
396-
moduleSymbol,
397-
moduleFile,
398-
defaultInfo.exportKind,
399-
isFromPackageJson,
400-
checker);
401-
}
402-
checker.forEachExportAndPropertyOfModule(moduleSymbol, (exported, key) => {
403-
if (exported !== defaultInfo?.symbol && isImportableSymbol(exported, checker) && addToSeen(seenExports, key)) {
384+
try {
385+
forEachExternalModuleToImportFrom(program, host, /*useAutoImportProvider*/ true, (moduleSymbol, moduleFile, program, isFromPackageJson) => {
386+
if (++moduleCount % 100 === 0) cancellationToken?.throwIfCancellationRequested();
387+
const seenExports = new Map<__String, true>();
388+
const checker = program.getTypeChecker();
389+
const defaultInfo = getDefaultLikeExportInfo(moduleSymbol, checker, compilerOptions);
390+
// Note: I think we shouldn't actually see resolved module symbols here, but weird merges
391+
// can cause it to happen: see 'completionsImport_mergedReExport.ts'
392+
if (defaultInfo && isImportableSymbol(defaultInfo.symbol, checker)) {
404393
cache.add(
405394
importingFile.path,
406-
exported,
407-
key,
395+
defaultInfo.symbol,
396+
defaultInfo.exportKind === ExportKind.Default ? InternalSymbolName.Default : InternalSymbolName.ExportEquals,
408397
moduleSymbol,
409398
moduleFile,
410-
ExportKind.Named,
399+
defaultInfo.exportKind,
411400
isFromPackageJson,
412401
checker);
413402
}
403+
checker.forEachExportAndPropertyOfModule(moduleSymbol, (exported, key) => {
404+
if (exported !== defaultInfo?.symbol && isImportableSymbol(exported, checker) && addToSeen(seenExports, key)) {
405+
cache.add(
406+
importingFile.path,
407+
exported,
408+
key,
409+
moduleSymbol,
410+
moduleFile,
411+
ExportKind.Named,
412+
isFromPackageJson,
413+
checker);
414+
}
415+
});
414416
});
415-
});
417+
}
418+
catch (err) {
419+
// Ensure cache is reset if operation is cancelled
420+
cache.clear();
421+
throw err;
422+
}
416423

417424
host.log?.(`getExportInfoMap: done in ${timestamp() - start} ms`);
418425
return cache;

0 commit comments

Comments
 (0)