Merge pull request #30524 from Microsoft/moduleResolutionError

Report output file not built error for any module resolution that ends up to source file
This commit is contained in:
Sheetal Nandi
2019-03-21 10:05:49 -07:00
committed by GitHub
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;
}

View File

@@ -284,6 +284,28 @@ namespace ts {
assertHasError("Issues a useful error", program.getSemanticDiagnostics(), Diagnostics.Output_file_0_has_not_been_built_from_source_file_1);
});
});
it("issues a nice error when the input file is missing when module reference is not relative", () => {
const spec: TestSpecification = {
"/alpha": {
files: { "/alpha/a.ts": "export const m: number = 3;" },
references: []
},
"/beta": {
files: { "/beta/b.ts": "import { m } from '@alpha/a'" },
references: ["../alpha"],
options: {
baseUrl: "./",
paths: {
"@alpha/*": ["/alpha/*"]
}
}
}
};
testProjectReferences(spec, "/beta/tsconfig.json", program => {
assertHasError("Issues a useful error", program.getSemanticDiagnostics(), Diagnostics.Output_file_0_has_not_been_built_from_source_file_1);
});
});
});
/**