From 9740bcc53418e8792a4dbb978059ff5a02b55c91 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 22 Sep 2022 18:33:09 -0700 Subject: [PATCH] Pluralized `hasInvalidatedResolution` -> `hasInvalidatedResolutions` (#50912) * Pluralize hasInvalidatedResolution to hasInvalidatedResolutions. * Accepted baselines. --- src/compiler/program.ts | 10 +++++----- src/compiler/resolutionCache.ts | 8 ++++---- src/compiler/types.ts | 4 ++-- src/compiler/watchPublic.ts | 18 +++++++++--------- src/server/project.ts | 4 ++-- src/services/services.ts | 6 +++--- src/services/types.ts | 2 +- .../unittests/reuseProgramStructure.ts | 2 +- src/testRunner/unittests/tscWatch/watchApi.ts | 8 ++++---- .../reference/api/tsserverlibrary.d.ts | 4 ++-- tests/baselines/reference/api/typescript.d.ts | 4 ++-- ...not-implement-hasInvalidatedResolutions.js} | 0 ...st-implements-hasInvalidatedResolutions.js} | 0 13 files changed, 35 insertions(+), 35 deletions(-) rename tests/baselines/reference/tscWatch/watchApi/{host-implements-does-not-implement-hasInvalidatedResolution.js => host-implements-does-not-implement-hasInvalidatedResolutions.js} (100%) rename tests/baselines/reference/tscWatch/watchApi/{host-implements-hasInvalidatedResolution.js => host-implements-hasInvalidatedResolutions.js} (100%) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 5b48d317db7df..74abd84b43665 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -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; diff --git a/src/compiler/resolutionCache.ts b/src/compiler/resolutionCache.ts index 27b863a3abf3c..732a1114229ff 100644 --- a/src/compiler/resolutionCache.ts +++ b/src/compiler/resolutionCache.ts @@ -14,7 +14,7 @@ namespace ts { removeResolutionsOfFile(filePath: Path): void; removeResolutionsFromProjectReferenceRedirects(filePath: Path): void; setFilesWithInvalidatedNonRelativeUnresolvedImports(filesWithUnresolvedImports: ESMap): 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); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f63c1f21078bc..66e55ab58b381 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -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; diff --git a/src/compiler/watchPublic.ts b/src/compiler/watchPublic.ts index 788a8856f3a58..26c6deb9a259a 100644 --- a/src/compiler/watchPublic.ts +++ b/src/compiler/watchPublic.ts @@ -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); diff --git a/src/server/project.ts b/src/server/project.ts index 8a45bab06057f..05e6442a84c42 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -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; diff --git a/src/services/services.ts b/src/services/services.ts index a2078b875a568..975e36b1dd40c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -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 | 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; } diff --git a/src/services/types.ts b/src/services/types.ts index d22416abb0b50..915b7b71c8394 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -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; diff --git a/src/testRunner/unittests/reuseProgramStructure.ts b/src/testRunner/unittests/reuseProgramStructure.ts index 3e9e5f2313441..eda2135323d9c 100644 --- a/src/testRunner/unittests/reuseProgramStructure.ts +++ b/src/testRunner/unittests/reuseProgramStructure.ts @@ -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 diff --git a/src/testRunner/unittests/tscWatch/watchApi.ts b/src/testRunner/unittests/tscWatch/watchApi.ts index cfcbc115a69f4..8182e276d9617 100644 --- a/src/testRunner/unittests/tscWatch/watchApi.ts +++ b/src/testRunner/unittests/tscWatch/watchApi.ts @@ -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); }); }); diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 7b3d74e82987d..575116ceed587 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -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 */ diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index d65d6e1054086..0e6b2559af02e 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -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 */ diff --git a/tests/baselines/reference/tscWatch/watchApi/host-implements-does-not-implement-hasInvalidatedResolution.js b/tests/baselines/reference/tscWatch/watchApi/host-implements-does-not-implement-hasInvalidatedResolutions.js similarity index 100% rename from tests/baselines/reference/tscWatch/watchApi/host-implements-does-not-implement-hasInvalidatedResolution.js rename to tests/baselines/reference/tscWatch/watchApi/host-implements-does-not-implement-hasInvalidatedResolutions.js diff --git a/tests/baselines/reference/tscWatch/watchApi/host-implements-hasInvalidatedResolution.js b/tests/baselines/reference/tscWatch/watchApi/host-implements-hasInvalidatedResolutions.js similarity index 100% rename from tests/baselines/reference/tscWatch/watchApi/host-implements-hasInvalidatedResolution.js rename to tests/baselines/reference/tscWatch/watchApi/host-implements-hasInvalidatedResolutions.js