Skip to content

Pluralized hasInvalidatedResolution -> hasInvalidatedResolutions #50912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -782,7 +782,7 @@ namespace ts {

function sourceFileNotUptoDate(sourceFile: SourceFile) {
return !sourceFileVersionUptoDate(sourceFile) ||
hasInvalidatedResolution(sourceFile.path);
hasInvalidatedResolutions(sourceFile.path);
}

function sourceFileVersionUptoDate(sourceFile: SourceFile) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions src/compiler/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -236,7 +236,7 @@ namespace ts {
invalidateResolutionOfFile,
invalidateResolutionsOfFailedLookupLocations,
setFilesWithInvalidatedNonRelativeUnresolvedImports,
createHasInvalidatedResolution,
createHasInvalidatedResolutions,
isFileWithInvalidatedNonRelativeUnresolvedImports,
updateTypeRootsWatch,
closeTypeRootsWatch,
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7179,7 +7179,7 @@ namespace ts {
}

/* @internal */
export type HasInvalidatedResolution = (sourceFile: Path) => boolean;
export type HasInvalidatedResolutions = (sourceFile: Path) => boolean;
/* @internal */
export type HasChangedAutomaticTypeDirectiveNames = () => boolean;

Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/compiler/watchPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -467,7 +467,7 @@ namespace ts {
if (reportFileChangeDetectedOnCreateProgram) {
reportWatchDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation);
}
createNewProgram(hasInvalidatedResolution);
createNewProgram(hasInvalidatedResolutions);
}

reportFileChangeDetectedOnCreateProgram = false;
Expand All @@ -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)}`);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ namespace ts.server {
readonly realpath?: (path: string) => string;

/*@internal*/
hasInvalidatedResolution: HasInvalidatedResolution | undefined;
hasInvalidatedResolutions: HasInvalidatedResolutions | undefined;

/*@internal*/
resolutionCache: ResolutionCache;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1332,7 +1332,7 @@ namespace ts {
},
onReleaseOldSourceFile,
onReleaseParsedCommandLine,
hasInvalidatedResolution,
hasInvalidatedResolutions,
hasChangedAutomaticTypeDirectiveNames,
trace: maybeBind(host, host.trace),
resolveModuleNames: maybeBind(host, host.resolveModuleNames),
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/reuseProgramStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/testRunner/unittests/tscWatch/watchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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",
Expand Down Expand Up @@ -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);
});
});

Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
*/
Expand Down
Loading