Skip to content

Commit 8ac4580

Browse files
committed
Add error related to file not in rootDir and file not part of included root files at the references
1 parent fd515b5 commit 8ac4580

File tree

13 files changed

+444
-143
lines changed

13 files changed

+444
-143
lines changed

src/compiler/program.ts

Lines changed: 170 additions & 53 deletions
Large diffs are not rendered by default.

src/compiler/types.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,6 +2914,20 @@ namespace ts {
29142914
throwIfCancellationRequested(): void;
29152915
}
29162916

2917+
/*@internal*/
2918+
export enum RefFileKind {
2919+
Import,
2920+
ReferenceFile,
2921+
TypeReferenceDirective
2922+
}
2923+
2924+
/*@internal*/
2925+
export interface RefFile {
2926+
kind: RefFileKind;
2927+
index: number;
2928+
file: Path;
2929+
}
2930+
29172931
// TODO: This should implement TypeCheckerHost but that's an internal type.
29182932
export interface Program extends ScriptReferenceHost {
29192933

@@ -2933,6 +2947,8 @@ namespace ts {
29332947
*/
29342948
/* @internal */
29352949
getMissingFilePaths(): ReadonlyArray<Path>;
2950+
/* @internal */
2951+
getRefFileMap(): MultiMap<RefFile> | undefined;
29362952

29372953
/**
29382954
* Emits the JavaScript and declaration files. If targetSourceFile is not specified, then

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ namespace ts {
192192
export function arrayToSet<T>(array: ReadonlyArray<T>, makeKey: (value: T) => string | undefined): Map<true>;
193193
export function arrayToSet<T>(array: ReadonlyArray<T>, makeKey: (value: T) => __String | undefined): UnderscoreEscapedMap<true>;
194194
export function arrayToSet(array: ReadonlyArray<any>, makeKey?: (value: any) => string | __String | undefined): Map<true> | UnderscoreEscapedMap<true> {
195-
return arrayToMap<any, true>(array, makeKey || (s => s), () => true);
195+
return arrayToMap<any, true>(array, makeKey || (s => s), returnTrue);
196196
}
197197

198198
export function cloneMap(map: SymbolTable): SymbolTable;

src/testRunner/unittests/config/projectReferences.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ namespace ts {
193193
};
194194

195195
testProjectReferences(spec, "/primary/tsconfig.json", program => {
196-
const errs = program.getOptionsDiagnostics();
196+
const errs = program.getSemanticDiagnostics(program.getSourceFile("/primary/a.ts"));
197197
assertHasError("Reports an error about b.ts not being in the list", errs, Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern);
198198
});
199199
});
@@ -343,8 +343,9 @@ namespace ts {
343343
}
344344
};
345345
testProjectReferences(spec, "/alpha/tsconfig.json", (program) => {
346-
assertHasError("Issues an error about the rootDir", program.getOptionsDiagnostics(), Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files);
347-
assertHasError("Issues an error about the fileList", program.getOptionsDiagnostics(), Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern);
346+
const semanticDiagnostics = program.getSemanticDiagnostics(program.getSourceFile("/alpha/src/a.ts"));
347+
assertHasError("Issues an error about the rootDir", semanticDiagnostics, Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files);
348+
assertHasError("Issues an error about the fileList", semanticDiagnostics, Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern);
348349
});
349350
});
350351
});

src/testRunner/unittests/tsbuild/demo.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace ts {
4242
interface VerifyBuild {
4343
modifyDiskLayout: (fs: vfs.FileSystem) => void;
4444
expectedExitStatus: ExitStatus;
45-
expectedDiagnostics: fakes.ExpectedDiagnostic[];
45+
expectedDiagnostics: (fs: vfs.FileSystem) => fakes.ExpectedDiagnostic[];
4646
expectedOutputs: readonly string[];
4747
notExpectedOutputs: readonly string[];
4848
}
@@ -54,7 +54,7 @@ namespace ts {
5454
const builder = createSolutionBuilder(host, ["/src/tsconfig.json"], { verbose: true });
5555
const exitStatus = builder.build();
5656
assert.equal(exitStatus, expectedExitStatus);
57-
host.assertDiagnosticMessages(...expectedDiagnostics);
57+
host.assertDiagnosticMessages(...expectedDiagnostics(fs));
5858
verifyOutputsPresent(fs, expectedOutputs);
5959
verifyOutputsAbsent(fs, notExpectedOutputs);
6060
}
@@ -63,7 +63,7 @@ namespace ts {
6363
verifyBuild({
6464
modifyDiskLayout: noop,
6565
expectedExitStatus: ExitStatus.Success,
66-
expectedDiagnostics: [
66+
expectedDiagnostics: () => [
6767
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json", "src/animals/tsconfig.json", "src/zoo/tsconfig.json", "src/tsconfig.json"),
6868
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/lib/core/utilities.js"],
6969
[Diagnostics.Building_project_0, "/src/core/tsconfig.json"],
@@ -91,7 +91,7 @@ namespace ts {
9191
]`
9292
),
9393
expectedExitStatus: ExitStatus.ProjectReferenceCycle_OutputsSkupped,
94-
expectedDiagnostics: [
94+
expectedDiagnostics: () => [
9595
getExpectedDiagnosticForProjectsInBuild("src/animals/tsconfig.json", "src/zoo/tsconfig.json", "src/core/tsconfig.json", "src/tsconfig.json"),
9696
errorDiagnostic([
9797
Diagnostics.Project_references_may_not_form_a_circular_graph_Cycle_detected_Colon_0,
@@ -117,16 +117,38 @@ namespace ts {
117117
`
118118
),
119119
expectedExitStatus: ExitStatus.DiagnosticsPresent_OutputsSkipped,
120-
expectedDiagnostics: [
120+
expectedDiagnostics: fs => [
121121
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json", "src/animals/tsconfig.json", "src/zoo/tsconfig.json", "src/tsconfig.json"),
122122
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/lib/core/utilities.js"],
123123
[Diagnostics.Building_project_0, "/src/core/tsconfig.json"],
124-
errorDiagnostic([Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/animal.ts", "/src/core"]),
125-
errorDiagnostic([Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/dog.ts", "/src/core"]),
126-
errorDiagnostic([Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/index.ts", "/src/core"]),
127-
errorDiagnostic([Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/animal.ts", "/src/core/tsconfig.json"]),
128-
errorDiagnostic([Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/dog.ts", "/src/core/tsconfig.json"]),
129-
errorDiagnostic([Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/index.ts", "/src/core/tsconfig.json"]),
124+
{
125+
message: [Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/animal.ts", "/src/core"],
126+
location: expectedLocationIndexOf(fs, "/src/animals/index.ts", `'./animal'`),
127+
},
128+
{
129+
message: [Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/animal.ts", "/src/core/tsconfig.json"],
130+
location: expectedLocationIndexOf(fs, "/src/animals/index.ts", `'./animal'`),
131+
},
132+
{
133+
message: [Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/dog.ts", "/src/core"],
134+
location: expectedLocationIndexOf(fs, "/src/animals/index.ts", `'./dog'`),
135+
},
136+
{
137+
message: [Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/dog.ts", "/src/core/tsconfig.json"],
138+
location: expectedLocationIndexOf(fs, "/src/animals/index.ts", `'./dog'`),
139+
},
140+
{
141+
message: [Diagnostics._0_is_declared_but_its_value_is_never_read, "A"],
142+
location: expectedLocationIndexOf(fs, "/src/core/utilities.ts", `import * as A from '../animals';`),
143+
},
144+
{
145+
message: [Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, "/src/animals/index.ts", "/src/core"],
146+
location: expectedLocationIndexOf(fs, "/src/core/utilities.ts", `'../animals'`),
147+
},
148+
{
149+
message: [Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern, "/src/animals/index.ts", "/src/core/tsconfig.json"],
150+
location: expectedLocationIndexOf(fs, "/src/core/utilities.ts", `'../animals'`),
151+
},
130152
[Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_has_errors, "src/animals/tsconfig.json", "src/core"],
131153
[Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_has_errors, "/src/animals/tsconfig.json", "/src/core"],
132154
[Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_was_not_built, "src/zoo/tsconfig.json", "src/animals"],

src/testRunner/unittests/tsbuild/emptyFiles.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ namespace ts {
1717
builder.build();
1818
host.assertDiagnosticMessages({
1919
message: [Diagnostics.The_files_list_in_config_file_0_is_empty, "/src/no-references/tsconfig.json"],
20-
location: {
21-
file: "/src/no-references/tsconfig.json",
22-
start: lastIndexOf(fs, "/src/no-references/tsconfig.json", "[]"),
23-
length: 2
24-
}
20+
location: expectedLocationLastIndexOf(fs, "/src/no-references/tsconfig.json", "[]"),
2521
});
2622

2723
// Check for outputs to not be written.

src/testRunner/unittests/tsbuild/helpers.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ namespace ts {
6262
return content.lastIndexOf(searchStr);
6363
}
6464

65+
export function expectedLocationIndexOf(fs: vfs.FileSystem, file: string, searchStr: string): fakes.ExpectedDiagnosticLocation {
66+
return {
67+
file,
68+
start: indexOf(fs, file, searchStr),
69+
length: searchStr.length
70+
};
71+
}
72+
73+
export function expectedLocationLastIndexOf(fs: vfs.FileSystem, file: string, searchStr: string): fakes.ExpectedDiagnosticLocation {
74+
return {
75+
file,
76+
start: lastIndexOf(fs, file, searchStr),
77+
length: searchStr.length
78+
};
79+
}
80+
6581
export function getTime() {
6682
let currentTime = 100;
6783
return { tick, time, touch };

src/testRunner/unittests/tsbuild/referencesWithRootDirInParent.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ namespace ts {
4545
[Diagnostics.Building_project_0, "/src/src/main/tsconfig.json"],
4646
{
4747
message: [Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_file_generated_by_referenced_project_1, "/src/dist/tsconfig.tsbuildinfo", "/src/src/other"],
48-
location: {
49-
file: "/src/src/main/tsconfig.json",
50-
start: indexOf(fs, "/src/src/main/tsconfig.json", `{ "path": "../other" }`),
51-
length: `{ "path": "../other" }`.length
52-
}
48+
location: expectedLocationIndexOf(fs, "/src/src/main/tsconfig.json", `{ "path": "../other" }`),
5349
}
5450
);
5551
verifyOutputsPresent(fs, allExpectedOutputs);
@@ -84,11 +80,7 @@ namespace ts {
8480
[Diagnostics.Building_project_0, "/src/src/main/tsconfig.json"],
8581
{
8682
message: [Diagnostics.Cannot_write_file_0_because_it_will_overwrite_tsbuildinfo_file_generated_by_referenced_project_1, "/src/dist/tsconfig.tsbuildinfo", "/src/src/other"],
87-
location: {
88-
file: "/src/src/main/tsconfig.json",
89-
start: indexOf(fs, "/src/src/main/tsconfig.json", `{"path":"../other"}`),
90-
length: `{"path":"../other"}`.length
91-
}
83+
location: expectedLocationIndexOf(fs, "/src/src/main/tsconfig.json", `{"path":"../other"}`),
9284
}
9385
);
9486
verifyOutputsPresent(fs, allExpectedOutputs);

src/testRunner/unittests/tsbuild/resolveJsonModule.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ namespace ts {
3030
it("with resolveJsonModule and include only", () => {
3131
verifyProjectWithResolveJsonModule(
3232
"/src/tsconfig_withInclude.json",
33-
errorDiagnostic([
34-
Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern,
35-
"/src/src/hello.json",
36-
"/src/tsconfig_withInclude.json"
37-
])
33+
{
34+
message: [
35+
Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern,
36+
"/src/src/hello.json",
37+
"/src/tsconfig_withInclude.json"
38+
],
39+
location: expectedLocationIndexOf(projFs, "/src/src/index.ts", `"./hello.json"`)
40+
}
3841
);
3942
});
4043

src/testRunner/unittests/tsbuild/sample.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,7 @@ namespace ts {
452452
[Diagnostics.Building_project_0, "/src/logic/tsconfig.json"],
453453
{
454454
message: [Diagnostics.Property_0_does_not_exist_on_type_1, "muitply", `typeof import("/src/core/index")`],
455-
location: {
456-
file: "/src/logic/index.ts",
457-
start: indexOf(fs, "/src/logic/index.ts", "muitply"),
458-
length: "muitply".length
459-
}
455+
location: expectedLocationIndexOf(fs, "/src/logic/index.ts", "muitply"),
460456
},
461457
[Diagnostics.Project_0_can_t_be_built_because_its_dependency_1_has_errors, "src/tests/tsconfig.json", "src/logic"],
462458
[Diagnostics.Skipping_build_of_project_0_because_its_dependency_1_has_errors, "/src/tests/tsconfig.json", "/src/logic"]

0 commit comments

Comments
 (0)