mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-17 00:34:47 -05:00
TypeReference directive reuse (#49750)
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
||||
ReadonlyESMap, removeSuffix, removeTrailingDirectorySeparator, resolutionExtensionIsTSOrJson, ResolvedModuleFull,
|
||||
ResolvedModuleWithFailedLookupLocations, ResolvedProjectReference, ResolvedTypeReferenceDirective,
|
||||
ResolvedTypeReferenceDirectiveWithFailedLookupLocations, returnTrue, Set, some, SourceFile, startsWith,
|
||||
stringContains, trace, unorderedRemoveItem, WatchDirectoryFlags,
|
||||
stringContains, trace, TypeReferenceDirectiveResolutionInfo, unorderedRemoveItem, WatchDirectoryFlags,
|
||||
} from "./_namespaces/ts";
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,13 @@ export interface ResolutionCache {
|
||||
resolutionInfo: ModuleResolutionInfo | undefined
|
||||
): (ResolvedModuleFull | undefined)[];
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache(moduleName: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): CachedResolvedModuleWithFailedLookupLocations | undefined;
|
||||
resolveTypeReferenceDirectives(typeDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference?: ResolvedProjectReference, containingFileMode?: SourceFile["impliedNodeFormat"]): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
resolveTypeReferenceDirectives(
|
||||
typeDirectiveNames: string[] | readonly FileReference[],
|
||||
containingFile: string,
|
||||
redirectedReference: ResolvedProjectReference | undefined,
|
||||
containingFileMode: SourceFile["impliedNodeFormat"] | undefined,
|
||||
resolutionInfo: TypeReferenceDirectiveResolutionInfo | undefined,
|
||||
): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
|
||||
invalidateResolutionsOfFailedLookupLocations(): boolean;
|
||||
invalidateResolutionOfFile(filePath: Path): void;
|
||||
@@ -445,7 +451,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
|
||||
getResolutionWithResolvedFileName: GetResolutionWithResolvedFileName<T, R>;
|
||||
shouldRetryResolution: (t: T) => boolean;
|
||||
reusedNames?: readonly string[];
|
||||
resolutionInfo?: ModuleResolutionInfo;
|
||||
resolutionInfo?: ModuleResolutionInfo | TypeReferenceDirectiveResolutionInfo;
|
||||
logChanges?: boolean;
|
||||
containingSourceFile?: SourceFile;
|
||||
containingSourceFileMode?: SourceFile["impliedNodeFormat"];
|
||||
@@ -479,7 +485,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
|
||||
const seenNamesInFile = createModeAwareCache<true>();
|
||||
let i = 0;
|
||||
for (const entry of containingSourceFile && resolutionInfo ? resolutionInfo.names : names) {
|
||||
const name = !isString(entry) ? getResolutionName(entry) : entry;
|
||||
const name = getResolutionName(entry);
|
||||
// Imports supply a `containingSourceFile` but no `containingSourceFileMode` - it would be redundant
|
||||
// they require calculating the mode for a given import from it's position in the resolution table, since a given
|
||||
// import's syntax may override the file's default mode.
|
||||
@@ -576,7 +582,13 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
|
||||
}
|
||||
|
||||
if (containingSourceFile && resolutionInfo) {
|
||||
resolutionInfo.reusedNames?.forEach(literal => seenNamesInFile.set(literal.text, getModeForUsageLocation(containingSourceFile, literal), true));
|
||||
resolutionInfo.reusedNames?.forEach(entry => seenNamesInFile.set(
|
||||
getResolutionName(entry),
|
||||
!isString(entry) && isStringLiteralLike(entry) ?
|
||||
getModeForUsageLocation(containingSourceFile, entry) :
|
||||
getModeForFileReference(entry, containingSourceFile.impliedNodeFormat),
|
||||
true,
|
||||
));
|
||||
reusedNames = undefined;
|
||||
}
|
||||
if (resolutionsInFile.size() !== seenNamesInFile.size()) {
|
||||
@@ -610,7 +622,13 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
|
||||
}
|
||||
}
|
||||
|
||||
function resolveTypeReferenceDirectives(typeDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference?: ResolvedProjectReference, containingFileMode?: SourceFile["impliedNodeFormat"]): (ResolvedTypeReferenceDirective | undefined)[] {
|
||||
function resolveTypeReferenceDirectives(
|
||||
typeDirectiveNames: string[] | readonly FileReference[],
|
||||
containingFile: string,
|
||||
redirectedReference?: ResolvedProjectReference,
|
||||
containingFileMode?: SourceFile["impliedNodeFormat"],
|
||||
resolutionInfo?: TypeReferenceDirectiveResolutionInfo,
|
||||
): (ResolvedTypeReferenceDirective | undefined)[] {
|
||||
return resolveNamesWithLocalCache<CachedResolvedTypeReferenceDirectiveWithFailedLookupLocations, ResolvedTypeReferenceDirective>({
|
||||
names: typeDirectiveNames,
|
||||
containingFile,
|
||||
@@ -620,7 +638,8 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
|
||||
loader: resolveTypeReferenceDirective,
|
||||
getResolutionWithResolvedFileName: getResolvedTypeReferenceDirective,
|
||||
shouldRetryResolution: resolution => resolution.resolvedTypeReferenceDirective === undefined,
|
||||
containingSourceFileMode: containingFileMode
|
||||
containingSourceFileMode: containingFileMode,
|
||||
resolutionInfo,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user