Refactoring

This commit is contained in:
Sheetal Nandi
2019-07-01 14:33:39 -07:00
parent f9e4b91203
commit f7ea0bab60
8 changed files with 16 additions and 14 deletions
+6 -1
View File
@@ -814,7 +814,7 @@ namespace ts {
let projectReferenceRedirects: Map<ResolvedProjectReference | false> | undefined;
let mapFromFileToProjectReferenceRedirects: Map<Path> | undefined;
let mapFromToProjectReferenceRedirectSource: Map<SourceOfProjectReferenceRedirect> | undefined;
const useSourceOfReference = useSourceInsteadOfReferenceRedirect(host);
const useSourceOfReference = !!host.useSourceInsteadOfReferenceRedirect && host.useSourceInsteadOfReferenceRedirect();
const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles(oldProgram, options);
const structuralIsReused = tryReuseStructureFromOldProgram();
@@ -964,6 +964,7 @@ namespace ts {
getResolvedProjectReferenceToRedirect,
getResolvedProjectReferenceByPath,
forEachResolvedProjectReference,
isSourceOfProjectReferenceRedirect,
emitBuildInfo
};
@@ -2496,6 +2497,10 @@ namespace ts {
return mapFromToProjectReferenceRedirectSource.get(toPath(file));
}
function isSourceOfProjectReferenceRedirect(fileName: string) {
return useSourceOfReference && !!getResolvedProjectReferenceToRedirect(fileName);
}
function forEachProjectReference<T>(
projectReferences: ReadonlyArray<ProjectReference> | undefined,
resolvedProjectReferences: ReadonlyArray<ResolvedProjectReference | undefined> | undefined,
+2
View File
@@ -2993,6 +2993,7 @@ namespace ts {
/*@internal*/ getResolvedProjectReferenceToRedirect(fileName: string): ResolvedProjectReference | undefined;
/*@internal*/ forEachResolvedProjectReference<T>(cb: (resolvedProjectReference: ResolvedProjectReference | undefined, resolvedProjectReferencePath: Path) => T | undefined): T | undefined;
/*@internal*/ getResolvedProjectReferenceByPath(projectReferencePath: Path): ResolvedProjectReference | undefined;
/*@internal*/ isSourceOfProjectReferenceRedirect(fileName: string): boolean;
/*@internal*/ getProgramBuildInfo?(): ProgramBuildInfo | undefined;
/*@internal*/ emitBuildInfo(writeFile?: WriteFileCallback, cancellationToken?: CancellationToken): EmitResult;
}
@@ -3090,6 +3091,7 @@ namespace ts {
getSourceFile(fileName: string): SourceFile | undefined;
getResolvedTypeReferenceDirectives(): ReadonlyMap<ResolvedTypeReferenceDirective | undefined>;
getProjectReferenceRedirect(fileName: string): string | undefined;
isSourceOfProjectReferenceRedirect(fileName: string): boolean;
readonly redirectTargetsMap: RedirectTargetsMap;
}
-4
View File
@@ -4616,10 +4616,6 @@ namespace ts {
return false;
}
}
export function useSourceInsteadOfReferenceRedirect(host: { useSourceInsteadOfReferenceRedirect?(): boolean; }) {
return host.useSourceInsteadOfReferenceRedirect && host.useSourceInsteadOfReferenceRedirect();
}
}
namespace ts {
+1 -1
View File
@@ -2570,7 +2570,7 @@ namespace ts.server {
/*@internal*/
getOriginalLocationEnsuringConfiguredProject(project: Project, location: DocumentPosition): DocumentPosition | undefined {
const originalLocation = useSourceInsteadOfReferenceRedirect(project) && project.getResolvedProjectReferenceToRedirect(location.fileName) ?
const originalLocation = project.isSourceOfProjectReferenceRedirect(location.fileName) ?
location :
project.getSourceMapper().tryGetSourcePosition(location);
if (!originalLocation) return undefined;
+5 -3
View File
@@ -196,9 +196,6 @@ namespace ts.server {
/*@internal*/
originalConfiguredProjects: Map<true> | undefined;
/*@internal*/
useSourceInsteadOfReferenceRedirect?: () => boolean;
/*@internal*/
getResolvedProjectReferenceToRedirect(_fileName: string): ResolvedProjectReference | undefined {
return undefined;
@@ -1231,6 +1228,11 @@ namespace ts.server {
this.rootFilesMap.delete(info.path);
}
/*@internal*/
isSourceOfProjectReferenceRedirect(fileName: string) {
return !!this.program && this.program.isSourceOfProjectReferenceRedirect(fileName);
}
protected enableGlobalPlugins(options: CompilerOptions, pluginConfigOverrides: Map<any> | undefined) {
const host = this.projectService.host;
+1 -1
View File
@@ -443,7 +443,7 @@ namespace ts.server {
function getDefinitionInProject(definition: DocumentPosition | undefined, definingProject: Project, project: Project): DocumentPosition | undefined {
if (!definition || project.containsFile(toNormalizedPath(definition.fileName))) return definition;
const mappedDefinition = useSourceInsteadOfReferenceRedirect(definingProject) && definingProject.getResolvedProjectReferenceToRedirect(definition.fileName) ?
const mappedDefinition = definingProject.isSourceOfProjectReferenceRedirect(definition.fileName) ?
definition :
definingProject.getLanguageService().getSourceMapper().tryGetGeneratedPosition(definition);
return mappedDefinition && project.containsFile(toNormalizedPath(mappedDefinition.fileName)) ? mappedDefinition : undefined;
-1
View File
@@ -1151,7 +1151,6 @@ namespace ts {
fileExists: maybeBind(host, host.fileExists),
readFile: maybeBind(host, host.readFile),
getDocumentPositionMapper: maybeBind(host, host.getDocumentPositionMapper),
useSourceInsteadOfReferenceRedirect: maybeBind(host, host.useSourceInsteadOfReferenceRedirect),
getSourceFileLike: maybeBind(host, host.getSourceFileLike),
log
});
+1 -3
View File
@@ -17,7 +17,6 @@ namespace ts {
readFile?(path: string, encoding?: string): string | undefined;
getSourceFileLike?(fileName: string): SourceFileLike | undefined;
getDocumentPositionMapper?(generatedFileName: string, sourceFileName?: string): DocumentPositionMapper | undefined;
/* @internal */ useSourceInsteadOfReferenceRedirect?(): boolean;
log(s: string): void;
}
@@ -72,8 +71,7 @@ namespace ts {
const program = host.getProgram()!;
// If this is source file of project reference source (instead of redirect) there is no generated position
if (useSourceInsteadOfReferenceRedirect(host) &&
program.getResolvedProjectReferenceToRedirect(sourceFile.fileName)) {
if (program.isSourceOfProjectReferenceRedirect(sourceFile.fileName)) {
return undefined;
}