From 57265375368483810b63aca74477f30a6ffd2cca Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 20 Jun 2019 15:39:33 -0700 Subject: [PATCH 1/2] Remove secondary reference lookup implementation --- src/compiler/emitter.ts | 3 ++- src/compiler/program.ts | 5 +++-- src/compiler/transformers/declarations.ts | 2 +- src/compiler/types.ts | 3 ++- src/compiler/utilities.ts | 7 ------- src/services/goToDefinition.ts | 2 +- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ddd273c360201..120154d277261 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -725,7 +725,8 @@ namespace ts { fileExists: f => host.fileExists(f), directoryExists: host.directoryExists && (f => host.directoryExists!(f)), useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(), - getProgramBuildInfo: returnUndefined + getProgramBuildInfo: returnUndefined, + getSourceFileFromReference: returnUndefined, // TODO: Implement? }; emitFiles( notImplementedResolver, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2b62da72d247f..f5ede694f8c7e 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1442,7 +1442,8 @@ namespace ts { }, ...(host.directoryExists ? { directoryExists: f => host.directoryExists!(f) } : {}), useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(), - getProgramBuildInfo: () => program.getProgramBuildInfo && program.getProgramBuildInfo() + getProgramBuildInfo: () => program.getProgramBuildInfo && program.getProgramBuildInfo(), + getSourceFileFromReference: (file, ref) => program.getSourceFileFromReference(file, ref), }; } @@ -2127,7 +2128,7 @@ namespace ts { } /** This should have similar behavior to 'processSourceFile' without diagnostics or mutation. */ - function getSourceFileFromReference(referencingFile: SourceFile, ref: FileReference): SourceFile | undefined { + function getSourceFileFromReference(referencingFile: SourceFile | UnparsedSource, ref: FileReference): SourceFile | undefined { return getSourceFileFromReferenceWorker(resolveTripleslashReference(ref.fileName, referencingFile.fileName), fileName => filesByName.get(toPath(fileName)) || undefined); } diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 03f08b4de5441..4f68c36d919c8 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -348,7 +348,7 @@ namespace ts { function collectReferences(sourceFile: SourceFile | UnparsedSource, ret: Map) { if (noResolve || (!isUnparsedSource(sourceFile) && isSourceFileJS(sourceFile))) return ret; forEach(sourceFile.referencedFiles, f => { - const elem = tryResolveScriptReference(host, sourceFile, f); + const elem = host.getSourceFileFromReference(sourceFile, f); if (elem) { ret.set("" + getOriginalNodeId(elem), elem); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ec46da039d976..4442f339d838e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2975,7 +2975,7 @@ namespace ts { // For testing purposes only. /* @internal */ structureIsReused?: StructureIsReused; - /* @internal */ getSourceFileFromReference(referencingFile: SourceFile, ref: FileReference): SourceFile | undefined; + /* @internal */ getSourceFileFromReference(referencingFile: SourceFile | UnparsedSource, ref: FileReference): SourceFile | undefined; /* @internal */ getLibFileFromReference(ref: FileReference): SourceFile | undefined; /** Given a source file, get the name of the package it was imported from. */ @@ -5399,6 +5399,7 @@ namespace ts { writeFile: WriteFileCallback; getProgramBuildInfo(): ProgramBuildInfo | undefined; + getSourceFileFromReference: Program["getSourceFileFromReference"]; } export interface TransformationContext { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 0e2488a02331c..ae5b60cd864c8 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2611,13 +2611,6 @@ namespace ts { return undefined; } - export function tryResolveScriptReference(host: ScriptReferenceHost, sourceFile: SourceFile | UnparsedSource, reference: FileReference) { - if (!host.getCompilerOptions().noResolve) { - const referenceFileName = isRootedDiskPath(reference.fileName) ? reference.fileName : combinePaths(getDirectoryPath(sourceFile.fileName), reference.fileName); - return host.getSourceFile(referenceFileName); - } - } - export function getAncestor(node: Node | undefined, kind: SyntaxKind): Node | undefined { while (node) { if (node.kind === kind) { diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index fbd0be91022f3..1cb42a59e3c9a 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -108,7 +108,7 @@ namespace ts.GoToDefinition { export function getReferenceAtPosition(sourceFile: SourceFile, position: number, program: Program): { fileName: string, file: SourceFile } | undefined { const referencePath = findReferenceInPosition(sourceFile.referencedFiles, position); if (referencePath) { - const file = tryResolveScriptReference(program, sourceFile, referencePath); + const file = program.getSourceFileFromReference(sourceFile, referencePath); return file && { fileName: referencePath.fileName, file }; } From abfacc7313b28e6617ac67bfe151b60ad17e71b6 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 21 Jun 2019 13:10:11 -0700 Subject: [PATCH 2/2] Remove TODO --- src/compiler/emitter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 120154d277261..f22451157ac45 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -726,7 +726,7 @@ namespace ts { directoryExists: host.directoryExists && (f => host.directoryExists!(f)), useCaseSensitiveFileNames: () => host.useCaseSensitiveFileNames(), getProgramBuildInfo: returnUndefined, - getSourceFileFromReference: returnUndefined, // TODO: Implement? + getSourceFileFromReference: returnUndefined, }; emitFiles( notImplementedResolver,