Skip to content

Commit e532f53

Browse files
Merge pull request #25531 from RyanCavanaugh/fix25527
Don't crash when an implicit rootDir constraint is violated under composite: true
2 parents 357f0d6 + 72f0789 commit e532f53

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2329,7 +2329,7 @@ namespace ts {
23292329
if (!sourceFile.isDeclarationFile) {
23302330
const absoluteSourceFilePath = host.getCanonicalFileName(getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory));
23312331
if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) {
2332-
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir));
2332+
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, rootDirectory));
23332333
allFilesBelongToPath = false;
23342334
}
23352335
}

src/testRunner/unittests/projectReferences.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,23 @@ namespace ts {
285285
});
286286
});
287287

288+
describe("errors when a file in a composite project occurs outside the root", () => {
289+
it("Errors when a file is outside the rootdir", () => {
290+
const spec: TestSpecification = {
291+
"/alpha": {
292+
files: { "/alpha/src/a.ts": "import * from '../../beta/b'", "/beta/b.ts": "export { }" },
293+
options: {
294+
declaration: true,
295+
outDir: "bin"
296+
},
297+
references: []
298+
}
299+
};
300+
testProjectReferences(spec, "/alpha/tsconfig.json", (program) => {
301+
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);
302+
assertHasError("Issues an error about the fileList", program.getOptionsDiagnostics(), Diagnostics.File_0_is_not_in_project_file_list_Projects_must_list_all_files_or_use_an_include_pattern);
303+
});
304+
});
305+
});
306+
288307
}

0 commit comments

Comments
 (0)