mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 12:32:08 -06:00
Pluralized hasInvalidatedResolution -> hasInvalidatedResolutions (#50912)
* Pluralize hasInvalidatedResolution to hasInvalidatedResolutions. * Accepted baselines.
This commit is contained in:
parent
a455955aac
commit
9740bcc534
@ -748,7 +748,7 @@ namespace ts {
|
||||
newOptions: CompilerOptions,
|
||||
getSourceVersion: (path: Path, fileName: string) => string | undefined,
|
||||
fileExists: (fileName: string) => boolean,
|
||||
hasInvalidatedResolution: HasInvalidatedResolution,
|
||||
hasInvalidatedResolutions: HasInvalidatedResolutions,
|
||||
hasChangedAutomaticTypeDirectiveNames: HasChangedAutomaticTypeDirectiveNames | undefined,
|
||||
getParsedCommandLine: (fileName: string) => ParsedCommandLine | undefined,
|
||||
projectReferences: readonly ProjectReference[] | undefined
|
||||
@ -782,7 +782,7 @@ namespace ts {
|
||||
|
||||
function sourceFileNotUptoDate(sourceFile: SourceFile) {
|
||||
return !sourceFileVersionUptoDate(sourceFile) ||
|
||||
hasInvalidatedResolution(sourceFile.path);
|
||||
hasInvalidatedResolutions(sourceFile.path);
|
||||
}
|
||||
|
||||
function sourceFileVersionUptoDate(sourceFile: SourceFile) {
|
||||
@ -1076,7 +1076,7 @@ namespace ts {
|
||||
let moduleResolutionCache: ModuleResolutionCache | undefined;
|
||||
let typeReferenceDirectiveResolutionCache: TypeReferenceDirectiveResolutionCache | undefined;
|
||||
let actualResolveModuleNamesWorker: (moduleNames: string[], containingFile: SourceFile, containingFileName: string, reusedNames?: string[], redirectedReference?: ResolvedProjectReference) => ResolvedModuleFull[];
|
||||
const hasInvalidatedResolution = host.hasInvalidatedResolution || returnFalse;
|
||||
const hasInvalidatedResolutions = host.hasInvalidatedResolutions || returnFalse;
|
||||
if (host.resolveModuleNames) {
|
||||
actualResolveModuleNamesWorker = (moduleNames, containingFile, containingFileName, reusedNames, redirectedReference) => host.resolveModuleNames!(Debug.checkEachDefined(moduleNames), containingFileName, reusedNames, redirectedReference, options, containingFile).map(resolved => {
|
||||
// An older host may have omitted extension, in which case we should infer it from the file extension of resolvedFileName.
|
||||
@ -1557,7 +1557,7 @@ namespace ts {
|
||||
for (let i = 0; i < moduleNames.length; i++) {
|
||||
const moduleName = moduleNames[i];
|
||||
// If the source file is unchanged and doesnt have invalidated resolution, reuse the module resolutions
|
||||
if (file === oldSourceFile && !hasInvalidatedResolution(oldSourceFile.path)) {
|
||||
if (file === oldSourceFile && !hasInvalidatedResolutions(oldSourceFile.path)) {
|
||||
const oldResolvedModule = getResolvedModule(oldSourceFile, moduleName, getModeForResolutionAtIndex(oldSourceFile, i));
|
||||
if (oldResolvedModule) {
|
||||
if (isTraceEnabled(options, host)) {
|
||||
@ -1822,7 +1822,7 @@ namespace ts {
|
||||
// tentatively approve the file
|
||||
modifiedSourceFiles.push({ oldFile: oldSourceFile, newFile: newSourceFile });
|
||||
}
|
||||
else if (hasInvalidatedResolution(oldSourceFile.path)) {
|
||||
else if (hasInvalidatedResolutions(oldSourceFile.path)) {
|
||||
// 'module/types' references could have changed
|
||||
structureIsReused = StructureIsReused.SafeModules;
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ namespace ts {
|
||||
removeResolutionsOfFile(filePath: Path): void;
|
||||
removeResolutionsFromProjectReferenceRedirects(filePath: Path): void;
|
||||
setFilesWithInvalidatedNonRelativeUnresolvedImports(filesWithUnresolvedImports: ESMap<Path, readonly string[]>): void;
|
||||
createHasInvalidatedResolution(customHasInvalidatedResolution: HasInvalidatedResolution): HasInvalidatedResolution;
|
||||
createHasInvalidatedResolutions(customHasInvalidatedResolutions: HasInvalidatedResolutions): HasInvalidatedResolutions;
|
||||
hasChangedAutomaticTypeDirectiveNames(): boolean;
|
||||
isFileWithInvalidatedNonRelativeUnresolvedImports(path: Path): boolean;
|
||||
|
||||
@ -236,7 +236,7 @@ namespace ts {
|
||||
invalidateResolutionOfFile,
|
||||
invalidateResolutionsOfFailedLookupLocations,
|
||||
setFilesWithInvalidatedNonRelativeUnresolvedImports,
|
||||
createHasInvalidatedResolution,
|
||||
createHasInvalidatedResolutions,
|
||||
isFileWithInvalidatedNonRelativeUnresolvedImports,
|
||||
updateTypeRootsWatch,
|
||||
closeTypeRootsWatch,
|
||||
@ -300,12 +300,12 @@ namespace ts {
|
||||
return !!value && !!value.length;
|
||||
}
|
||||
|
||||
function createHasInvalidatedResolution(customHasInvalidatedResolution: HasInvalidatedResolution): HasInvalidatedResolution {
|
||||
function createHasInvalidatedResolutions(customHasInvalidatedResolutions: HasInvalidatedResolutions): HasInvalidatedResolutions {
|
||||
// Ensure pending resolutions are applied
|
||||
invalidateResolutionsOfFailedLookupLocations();
|
||||
const collected = filesWithInvalidatedResolutions;
|
||||
filesWithInvalidatedResolutions = undefined;
|
||||
return path => customHasInvalidatedResolution(path) ||
|
||||
return path => customHasInvalidatedResolutions(path) ||
|
||||
!!collected?.has(path) ||
|
||||
isFileWithInvalidatedNonRelativeUnresolvedImports(path);
|
||||
}
|
||||
|
||||
@ -7179,7 +7179,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export type HasInvalidatedResolution = (sourceFile: Path) => boolean;
|
||||
export type HasInvalidatedResolutions = (sourceFile: Path) => boolean;
|
||||
/* @internal */
|
||||
export type HasChangedAutomaticTypeDirectiveNames = () => boolean;
|
||||
|
||||
@ -7216,7 +7216,7 @@ namespace ts {
|
||||
/* @internal */ onReleaseOldSourceFile?(oldSourceFile: SourceFile, oldOptions: CompilerOptions, hasSourceFileByPath: boolean): void;
|
||||
/* @internal */ onReleaseParsedCommandLine?(configFileName: string, oldResolvedRef: ResolvedProjectReference | undefined, optionOptions: CompilerOptions): void;
|
||||
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
|
||||
hasInvalidatedResolution?(filePath: Path): boolean;
|
||||
hasInvalidatedResolutions?(filePath: Path): boolean;
|
||||
/* @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames;
|
||||
createHash?(data: string): string;
|
||||
getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined;
|
||||
|
||||
@ -113,7 +113,7 @@ namespace ts {
|
||||
/** If provided, used to resolve type reference directives, otherwise typescript's default resolution */
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
|
||||
hasInvalidatedResolution?(filePath: Path): boolean;
|
||||
hasInvalidatedResolutions?(filePath: Path): boolean;
|
||||
/**
|
||||
* Returns the module resolution cache used by a provided `resolveModuleNames` implementation so that any non-name module resolution operations (eg, package.json lookup) can reuse it
|
||||
*/
|
||||
@ -373,9 +373,9 @@ namespace ts {
|
||||
maybeBind(host, host.getModuleResolutionCache) :
|
||||
(() => resolutionCache.getModuleResolutionCache());
|
||||
const userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
|
||||
// All resolutions are invalid if user provided resolutions and didnt supply hasInvalidatedResolution
|
||||
const customHasInvalidatedResolution = userProvidedResolution ?
|
||||
maybeBind(host, host.hasInvalidatedResolution) || returnTrue :
|
||||
// All resolutions are invalid if user provided resolutions and didnt supply hasInvalidatedResolutions
|
||||
const customHasInvalidatedResolutions = userProvidedResolution ?
|
||||
maybeBind(host, host.hasInvalidatedResolutions) || returnTrue :
|
||||
returnFalse;
|
||||
|
||||
builderProgram = readBuilderProgram(compilerOptions, compilerHost) as any as T;
|
||||
@ -449,12 +449,12 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
const hasInvalidatedResolution = resolutionCache.createHasInvalidatedResolution(customHasInvalidatedResolution);
|
||||
const hasInvalidatedResolutions = resolutionCache.createHasInvalidatedResolutions(customHasInvalidatedResolutions);
|
||||
const {
|
||||
originalReadFile, originalFileExists, originalDirectoryExists,
|
||||
originalCreateDirectory, originalWriteFile,
|
||||
} = changeCompilerHostLikeToUseCache(compilerHost, toPath);
|
||||
if (isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, fileName => compilerHost.fileExists(fileName), hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
|
||||
if (isProgramUptoDate(getCurrentProgram(), rootFileNames, compilerOptions, getSourceVersion, fileName => compilerHost.fileExists(fileName), hasInvalidatedResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
|
||||
if (hasChangedConfigFileParsingErrors) {
|
||||
if (reportFileChangeDetectedOnCreateProgram) {
|
||||
reportWatchDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation);
|
||||
@ -467,7 +467,7 @@ namespace ts {
|
||||
if (reportFileChangeDetectedOnCreateProgram) {
|
||||
reportWatchDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation);
|
||||
}
|
||||
createNewProgram(hasInvalidatedResolution);
|
||||
createNewProgram(hasInvalidatedResolutions);
|
||||
}
|
||||
|
||||
reportFileChangeDetectedOnCreateProgram = false;
|
||||
@ -484,7 +484,7 @@ namespace ts {
|
||||
return builderProgram;
|
||||
}
|
||||
|
||||
function createNewProgram(hasInvalidatedResolution: HasInvalidatedResolution) {
|
||||
function createNewProgram(hasInvalidatedResolutions: HasInvalidatedResolutions) {
|
||||
// Compile the program
|
||||
writeLog("CreatingProgramWith::");
|
||||
writeLog(` roots: ${JSON.stringify(rootFileNames)}`);
|
||||
@ -495,7 +495,7 @@ namespace ts {
|
||||
hasChangedCompilerOptions = false;
|
||||
hasChangedConfigFileParsingErrors = false;
|
||||
resolutionCache.startCachingPerDirectoryResolution();
|
||||
compilerHost.hasInvalidatedResolution = hasInvalidatedResolution;
|
||||
compilerHost.hasInvalidatedResolutions = hasInvalidatedResolutions;
|
||||
compilerHost.hasChangedAutomaticTypeDirectiveNames = hasChangedAutomaticTypeDirectiveNames;
|
||||
const oldProgram = getCurrentProgram();
|
||||
builderProgram = createProgram(rootFileNames, compilerOptions, compilerHost, builderProgram, configFileParsingDiagnostics, projectReferences);
|
||||
|
||||
@ -172,7 +172,7 @@ namespace ts.server {
|
||||
readonly realpath?: (path: string) => string;
|
||||
|
||||
/*@internal*/
|
||||
hasInvalidatedResolution: HasInvalidatedResolution | undefined;
|
||||
hasInvalidatedResolutions: HasInvalidatedResolutions | undefined;
|
||||
|
||||
/*@internal*/
|
||||
resolutionCache: ResolutionCache;
|
||||
@ -1176,7 +1176,7 @@ namespace ts.server {
|
||||
Debug.assert(!this.isClosed(), "Called update graph worker of closed project");
|
||||
this.writeLog(`Starting updateGraphWorker: Project: ${this.getProjectName()}`);
|
||||
const start = timestamp();
|
||||
this.hasInvalidatedResolution = this.resolutionCache.createHasInvalidatedResolution(returnFalse);
|
||||
this.hasInvalidatedResolutions = this.resolutionCache.createHasInvalidatedResolutions(returnFalse);
|
||||
this.resolutionCache.startCachingPerDirectoryResolution();
|
||||
this.program = this.languageService.getProgram(); // TODO: GH#18217
|
||||
this.dirty = false;
|
||||
|
||||
@ -1300,7 +1300,7 @@ namespace ts {
|
||||
|
||||
// Get a fresh cache of the host information
|
||||
const newSettings = host.getCompilationSettings() || getDefaultCompilerOptions();
|
||||
const hasInvalidatedResolution: HasInvalidatedResolution = host.hasInvalidatedResolution || returnFalse;
|
||||
const hasInvalidatedResolutions: HasInvalidatedResolutions = host.hasInvalidatedResolutions || returnFalse;
|
||||
const hasChangedAutomaticTypeDirectiveNames = maybeBind(host, host.hasChangedAutomaticTypeDirectiveNames);
|
||||
const projectReferences = host.getProjectReferences?.();
|
||||
let parsedCommandLines: ESMap<Path, ParsedCommandLine | false> | undefined;
|
||||
@ -1332,7 +1332,7 @@ namespace ts {
|
||||
},
|
||||
onReleaseOldSourceFile,
|
||||
onReleaseParsedCommandLine,
|
||||
hasInvalidatedResolution,
|
||||
hasInvalidatedResolutions,
|
||||
hasChangedAutomaticTypeDirectiveNames,
|
||||
trace: maybeBind(host, host.trace),
|
||||
resolveModuleNames: maybeBind(host, host.resolveModuleNames),
|
||||
@ -1369,7 +1369,7 @@ namespace ts {
|
||||
const documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings);
|
||||
|
||||
// If the program is already up-to-date, we can reuse it
|
||||
if (isProgramUptoDate(program, rootFileNames, newSettings, (_path, fileName) => host.getScriptVersion(fileName), fileName => compilerHost!.fileExists(fileName), hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
|
||||
if (isProgramUptoDate(program, rootFileNames, newSettings, (_path, fileName) => host.getScriptVersion(fileName), fileName => compilerHost!.fileExists(fileName), hasInvalidatedResolutions, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@ -287,7 +287,7 @@ namespace ts {
|
||||
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingSourceFile?: SourceFile): (ResolvedModule | undefined)[];
|
||||
getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string, resolutionMode?: ModuleKind.CommonJS | ModuleKind.ESNext): ResolvedModuleWithFailedLookupLocations | undefined;
|
||||
resolveTypeReferenceDirectives?(typeDirectiveNames: string[] | FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
/* @internal */ hasInvalidatedResolution?: HasInvalidatedResolution;
|
||||
/* @internal */ hasInvalidatedResolutions?: HasInvalidatedResolutions;
|
||||
/* @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames;
|
||||
/* @internal */ getGlobalTypingsCacheLocation?(): string | undefined;
|
||||
/* @internal */ getSymlinkCache?(files?: readonly SourceFile[]): SymlinkCache;
|
||||
|
||||
@ -934,7 +934,7 @@ namespace ts {
|
||||
return isProgramUptoDate(
|
||||
program, newRootFileNames, newOptions,
|
||||
path => program.getSourceFileByPath(path)!.version, /*fileExists*/ returnFalse,
|
||||
/*hasInvalidatedResolution*/ returnFalse,
|
||||
/*hasInvalidatedResolutions*/ returnFalse,
|
||||
/*hasChangedAutomaticTypeDirectiveNames*/ undefined,
|
||||
/*getParsedCommandLine*/ returnUndefined,
|
||||
/*projectReferences*/ undefined
|
||||
|
||||
@ -50,7 +50,7 @@ namespace ts.tscWatch {
|
||||
});
|
||||
});
|
||||
|
||||
describe("hasInvalidatedResolution", () => {
|
||||
describe("hasInvalidatedResolutions", () => {
|
||||
function verifyWatch(subScenario: string, implementHasInvalidatedResolution: boolean) {
|
||||
it(subScenario, () => {
|
||||
const { sys, baseline, oldSnap, cb, getPrograms } = createBaseline(createWatchedSystem({
|
||||
@ -70,7 +70,7 @@ namespace ts.tscWatch {
|
||||
host.resolveModuleNames = (moduleNames, containingFile, _reusedNames, _redirectedReference, options) =>
|
||||
moduleNames.map(m => resolveModuleName(m, containingFile, options, host).resolvedModule);
|
||||
// Invalidate resolutions only when ts file is created
|
||||
if (implementHasInvalidatedResolution) host.hasInvalidatedResolution = () => sys.fileExists(`${projectRoot}/other.ts`);
|
||||
if (implementHasInvalidatedResolution) host.hasInvalidatedResolutions = () => sys.fileExists(`${projectRoot}/other.ts`);
|
||||
const watch = createWatchProgram(host);
|
||||
runWatchBaseline({
|
||||
scenario: "watchApi",
|
||||
@ -104,8 +104,8 @@ namespace ts.tscWatch {
|
||||
});
|
||||
});
|
||||
}
|
||||
verifyWatch("host implements does not implement hasInvalidatedResolution", /*implementHasInvalidatedResolution*/ false);
|
||||
verifyWatch("host implements hasInvalidatedResolution", /*implementHasInvalidatedResolution*/ true);
|
||||
verifyWatch("host implements does not implement hasInvalidatedResolutions", /*implementHasInvalidatedResolution*/ false);
|
||||
verifyWatch("host implements hasInvalidatedResolutions", /*implementHasInvalidatedResolution*/ true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -3321,7 +3321,7 @@ declare namespace ts {
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
getEnvironmentVariable?(name: string): string | undefined;
|
||||
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
|
||||
hasInvalidatedResolution?(filePath: Path): boolean;
|
||||
hasInvalidatedResolutions?(filePath: Path): boolean;
|
||||
createHash?(data: string): string;
|
||||
getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined;
|
||||
}
|
||||
@ -5445,7 +5445,7 @@ declare namespace ts {
|
||||
/** If provided, used to resolve type reference directives, otherwise typescript's default resolution */
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
|
||||
hasInvalidatedResolution?(filePath: Path): boolean;
|
||||
hasInvalidatedResolutions?(filePath: Path): boolean;
|
||||
/**
|
||||
* Returns the module resolution cache used by a provided `resolveModuleNames` implementation so that any non-name module resolution operations (eg, package.json lookup) can reuse it
|
||||
*/
|
||||
|
||||
@ -3321,7 +3321,7 @@ declare namespace ts {
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
getEnvironmentVariable?(name: string): string | undefined;
|
||||
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
|
||||
hasInvalidatedResolution?(filePath: Path): boolean;
|
||||
hasInvalidatedResolutions?(filePath: Path): boolean;
|
||||
createHash?(data: string): string;
|
||||
getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined;
|
||||
}
|
||||
@ -5445,7 +5445,7 @@ declare namespace ts {
|
||||
/** If provided, used to resolve type reference directives, otherwise typescript's default resolution */
|
||||
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[] | readonly FileReference[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions, containingFileMode?: SourceFile["impliedNodeFormat"] | undefined): (ResolvedTypeReferenceDirective | undefined)[];
|
||||
/** If provided along with custom resolveModuleNames or resolveTypeReferenceDirectives, used to determine if unchanged file path needs to re-resolve modules/type reference directives */
|
||||
hasInvalidatedResolution?(filePath: Path): boolean;
|
||||
hasInvalidatedResolutions?(filePath: Path): boolean;
|
||||
/**
|
||||
* Returns the module resolution cache used by a provided `resolveModuleNames` implementation so that any non-name module resolution operations (eg, package.json lookup) can reuse it
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user