Report output file not built error for any module resolution that ends up to source file

Fixes #29918
This commit is contained in:
Sheetal Nandi
2019-03-20 17:27:19 -07:00
parent 2932421370
commit 8da384d32a
4 changed files with 29 additions and 20 deletions

View File

@@ -2352,19 +2352,12 @@ namespace ts {
}
if (moduleNotFoundError) {
// For relative paths, see if this was possibly a projectReference redirect
if (pathIsRelative(moduleReference)) {
const sourceFile = getSourceFileOfNode(location);
const redirects = sourceFile.redirectedReferences;
if (redirects) {
const normalizedTargetPath = getNormalizedAbsolutePath(moduleReference, getDirectoryPath(sourceFile.fileName));
for (const ext of [Extension.Ts, Extension.Tsx]) {
const probePath = normalizedTargetPath + ext;
if (redirects.indexOf(probePath) >= 0) {
error(errorNode, Diagnostics.Output_file_0_has_not_been_built_from_source_file_1, moduleReference, probePath);
return undefined;
}
}
// See if this was possibly a projectReference redirect
if (resolvedModule) {
const redirect = host.getProjectReferenceRedirect(resolvedModule.resolvedFileName);
if (redirect) {
error(errorNode, Diagnostics.Output_file_0_has_not_been_built_from_source_file_1, redirect, resolvedModule.resolvedFileName);
return undefined;
}
}

View File

@@ -2268,7 +2268,6 @@ namespace ts {
if (refFile) {
const redirect = getProjectReferenceRedirect(fileName);
if (redirect) {
((refFile.redirectedReferences || (refFile.redirectedReferences = [])) as string[]).push(fileName);
fileName = redirect;
// Once we start redirecting to a file, we can potentially come back to it
// via a back-reference from another file in the .d.ts folder. If that happens we'll

View File

@@ -2740,12 +2740,6 @@ namespace ts {
/* @internal */ resolvedModules?: Map<ResolvedModuleFull | undefined>;
/* @internal */ resolvedTypeReferenceDirectiveNames: Map<ResolvedTypeReferenceDirective | undefined>;
/* @internal */ imports: ReadonlyArray<StringLiteralLike>;
/**
* When a file's references are redirected due to project reference directives,
* the original names of the references are stored in this array
*/
/* @internal*/
redirectedReferences?: ReadonlyArray<string>;
// Identifier only if `declare global`
/* @internal */ moduleAugmentations: ReadonlyArray<StringLiteral | Identifier>;
/* @internal */ patternAmbientModules?: PatternAmbientModule[];
@@ -3074,6 +3068,7 @@ namespace ts {
getSourceFiles(): ReadonlyArray<SourceFile>;
getSourceFile(fileName: string): SourceFile | undefined;
getResolvedTypeReferenceDirectives(): ReadonlyMap<ResolvedTypeReferenceDirective | undefined>;
getProjectReferenceRedirect(fileName: string): string | undefined;
readonly redirectTargetsMap: RedirectTargetsMap;
}