Skip to content
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

Fix type reference directive resolution #936

Merged
merged 2 commits into from May 18, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 14 additions & 7 deletions src/servicesHost.ts
Expand Up @@ -69,7 +69,9 @@ export function makeServicesHost(
fileExists,
readFile: readFileWithFallback,
realpath: compiler.sys.realpath,
directoryExists: compiler.sys.directoryExists
directoryExists: compiler.sys.directoryExists,
getCurrentDirectory: compiler.sys.getCurrentDirectory,
getDirectories: compiler.sys.getDirectories
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I understand this correctly, the fix is the implementation of these:

    directoryExists: compiler.sys.directoryExists,
    getCurrentDirectory: compiler.sys.getCurrentDirectory,
    getDirectories: compiler.sys.getDirectories

?

That's interesting. I wish it was more "fail fast" here if it actually needed these...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, specifically getCurrentDirectory. I agree. I'll suggest something like this to the team.


const clearCache = enableFileCaching ? addCache(moduleResolutionHost) : null;
Expand Down Expand Up @@ -187,8 +189,11 @@ function makeResolvers(
): (typescript.ResolvedTypeReferenceDirective | undefined)[] =>
typeDirectiveNames.map(
directive =>
resolveTypeReferenceDirective(directive, containingFile)
.resolvedTypeReferenceDirective
resolveTypeReferenceDirective(
directive,
containingFile,
_redirectedReference
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't related to the particular repro provided, but it seemed like a place that might be broken for even edgier edge cases

).resolvedTypeReferenceDirective
);

const resolveModuleName = makeResolveModuleName(
Expand Down Expand Up @@ -500,7 +505,8 @@ export function makeWatchHost(

type ResolveTypeReferenceDirective = (
directive: string,
containingFile: string
containingFile: string,
redirectedReference?: typescript.ResolvedProjectReference
) => typescript.ResolvedTypeReferenceDirectiveWithFailedLookupLocations;

function makeResolveTypeReferenceDirective(
Expand All @@ -512,16 +518,17 @@ function makeResolveTypeReferenceDirective(
| undefined
): ResolveTypeReferenceDirective {
if (customResolveTypeReferenceDirective === undefined) {
return (directive: string, containingFile: string) =>
return (directive, containingFile, redirectedReference) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contextual parameter types FTW 😄

compiler.resolveTypeReferenceDirective(
directive,
containingFile,
compilerOptions,
moduleResolutionHost
moduleResolutionHost,
redirectedReference
);
}

return (directive: string, containingFile: string) =>
return (directive, containingFile) =>
customResolveTypeReferenceDirective(
directive,
containingFile,
Expand Down