Skip to content

Commit 5813907

Browse files
author
Josh Goldberg
authored
Made TS6059 rootDir validation consistent for programmatic usage (#43145)
* Made TS6059 rootDir validation consistent for programmatic usage * Corrected other baselines
1 parent 6a83ae1 commit 5813907

File tree

7 files changed

+81
-2
lines changed

7 files changed

+81
-2
lines changed

src/compiler/program.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3195,9 +3195,10 @@ namespace ts {
31953195
}
31963196
}
31973197

3198-
// there has to be common source directory if user specified --outdir || --sourceRoot
3198+
// there has to be common source directory if user specified --outdir || --rootDir || --sourceRoot
31993199
// if user specified --mapRoot, there needs to be common source directory if there would be multiple files being emitted
32003200
if (options.outDir || // there is --outDir specified
3201+
options.rootDir || // there is --rootDir specified
32013202
options.sourceRoot || // there is --sourceRoot specified
32023203
options.mapRoot) { // there is --mapRoot specified
32033204

src/testRunner/unittests/services/transpile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ var x = 0;`, {
372372
});
373373

374374
transpilesCorrectly("Supports setting 'rootDir'", "x;", {
375-
options: { compilerOptions: { rootDir: "./rootDir" }, fileName: "input.js", reportDiagnostics: true }
375+
options: { compilerOptions: { rootDir: "./rootDir" }, fileName: "./rootDir/input.js", reportDiagnostics: true }
376376
});
377377

378378
transpilesCorrectly("Supports setting 'rootDirs'", "x;", {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error TS6059: File 'FolderA/FolderB/fileB.ts' is not under 'rootDir' 'FolderA/FolderB/FolderC'. 'rootDir' is expected to contain all source files.
2+
The file is in the program because:
3+
Root file specified for compilation
4+
5+
6+
!!! error TS6059: File 'FolderA/FolderB/fileB.ts' is not under 'rootDir' 'FolderA/FolderB/FolderC'. 'rootDir' is expected to contain all source files.
7+
!!! error TS6059: The file is in the program because:
8+
!!! error TS6059: Root file specified for compilation
9+
==== FolderA/FolderB/FolderC/fileC.ts (0 errors) ====
10+
class C {
11+
}
12+
13+
==== FolderA/FolderB/fileB.ts (0 errors) ====
14+
/// <reference path='FolderC/fileC.ts'/>
15+
class B {
16+
public c: C;
17+
}
18+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"scenario": "rootDirectory: Files outside the rootDirectory without outDir",
3+
"projectRoot": "tests/cases/projects/rootDirectory",
4+
"inputFiles": [
5+
"FolderA/FolderB/fileB.ts"
6+
],
7+
"rootDir": "FolderA/FolderB/FolderC",
8+
"resolvedInputFiles": [
9+
"lib.es5.d.ts",
10+
"FolderA/FolderB/FolderC/fileC.ts",
11+
"FolderA/FolderB/fileB.ts"
12+
],
13+
"emittedFiles": [
14+
"FolderA/FolderB/FolderC/fileC.js",
15+
"FolderA/FolderB/fileB.js"
16+
]
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error TS6059: File 'FolderA/FolderB/fileB.ts' is not under 'rootDir' 'FolderA/FolderB/FolderC'. 'rootDir' is expected to contain all source files.
2+
The file is in the program because:
3+
Root file specified for compilation
4+
5+
6+
!!! error TS6059: File 'FolderA/FolderB/fileB.ts' is not under 'rootDir' 'FolderA/FolderB/FolderC'. 'rootDir' is expected to contain all source files.
7+
!!! error TS6059: The file is in the program because:
8+
!!! error TS6059: Root file specified for compilation
9+
==== FolderA/FolderB/FolderC/fileC.ts (0 errors) ====
10+
class C {
11+
}
12+
13+
==== FolderA/FolderB/fileB.ts (0 errors) ====
14+
/// <reference path='FolderC/fileC.ts'/>
15+
class B {
16+
public c: C;
17+
}
18+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"scenario": "rootDirectory: Files outside the rootDirectory without outDir",
3+
"projectRoot": "tests/cases/projects/rootDirectory",
4+
"inputFiles": [
5+
"FolderA/FolderB/fileB.ts"
6+
],
7+
"rootDir": "FolderA/FolderB/FolderC",
8+
"resolvedInputFiles": [
9+
"lib.es5.d.ts",
10+
"FolderA/FolderB/FolderC/fileC.ts",
11+
"FolderA/FolderB/fileB.ts"
12+
],
13+
"emittedFiles": [
14+
"FolderA/FolderB/FolderC/fileC.js",
15+
"FolderA/FolderB/fileB.js"
16+
]
17+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"scenario": "rootDirectory: Files outside the rootDirectory without outDir",
3+
"projectRoot": "tests/cases/projects/rootDirectory",
4+
"inputFiles": [
5+
"FolderA/FolderB/fileB.ts"
6+
],
7+
"rootDir": "FolderA/FolderB/FolderC"
8+
}

0 commit comments

Comments
 (0)