Skip to content

Commit 4c378c0

Browse files
authored
Report config file parsing diagnostics correctly with tsc --b (microsoft#36520)
* Refactor the test * Add tests for syntax errors in tsconfig not being reported * Report config file parsing diagnostics correctly Fixes microsoft#36515 * Fix errors in existing tests for unintended tsconfig parse errors * Fix lint
1 parent c1e45ac commit 4c378c0

File tree

34 files changed

+543
-84
lines changed

34 files changed

+543
-84
lines changed

src/compiler/tsbuildPublic.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ namespace ts {
828828
if (state.options.verbose) reportStatus(state, Diagnostics.Building_project_0, project);
829829

830830
if (config.fileNames.length === 0) {
831-
reportAndStoreErrors(state, projectPath, config.errors);
831+
reportAndStoreErrors(state, projectPath, getConfigFileParsingDiagnostics(config));
832832
// Nothing to build - must be a solution file, basically
833833
buildResult = BuildResultFlags.None;
834834
step = Step.QueueReferencingProjects;
@@ -846,7 +846,7 @@ namespace ts {
846846
config.options,
847847
compilerHost,
848848
getOldProgram(state, projectPath, config),
849-
config.errors,
849+
getConfigFileParsingDiagnostics(config),
850850
config.projectReferences
851851
);
852852
step++;
@@ -1118,7 +1118,7 @@ namespace ts {
11181118
function needsBuild({ options }: SolutionBuilderState, status: UpToDateStatus, config: ParsedCommandLine) {
11191119
if (status.type !== UpToDateStatusType.OutOfDateWithPrepend || options.force) return true;
11201120
return config.fileNames.length === 0 ||
1121-
!!config.errors.length ||
1121+
!!getConfigFileParsingDiagnostics(config).length ||
11221122
!isIncrementalCompilation(config.options);
11231123
}
11241124

@@ -1172,7 +1172,7 @@ namespace ts {
11721172
verboseReportProjectStatus(state, project, status);
11731173
if (!options.force) {
11741174
if (status.type === UpToDateStatusType.UpToDate) {
1175-
reportAndStoreErrors(state, projectPath, config.errors);
1175+
reportAndStoreErrors(state, projectPath, getConfigFileParsingDiagnostics(config));
11761176
projectPendingBuild.delete(projectPath);
11771177
// Up to date, skip
11781178
if (options.dry) {
@@ -1183,7 +1183,7 @@ namespace ts {
11831183
}
11841184

11851185
if (status.type === UpToDateStatusType.UpToDateWithUpstreamTypes) {
1186-
reportAndStoreErrors(state, projectPath, config.errors);
1186+
reportAndStoreErrors(state, projectPath, getConfigFileParsingDiagnostics(config));
11871187
return createUpdateOutputFileStampsProject(
11881188
state,
11891189
project,
@@ -1195,7 +1195,7 @@ namespace ts {
11951195
}
11961196

11971197
if (status.type === UpToDateStatusType.UpstreamBlocked) {
1198-
reportAndStoreErrors(state, projectPath, config.errors);
1198+
reportAndStoreErrors(state, projectPath, getConfigFileParsingDiagnostics(config));
11991199
projectPendingBuild.delete(projectPath);
12001200
if (options.verbose) {
12011201
reportStatus(
@@ -1211,7 +1211,7 @@ namespace ts {
12111211
}
12121212

12131213
if (status.type === UpToDateStatusType.ContainerOnly) {
1214-
reportAndStoreErrors(state, projectPath, config.errors);
1214+
reportAndStoreErrors(state, projectPath, getConfigFileParsingDiagnostics(config));
12151215
projectPendingBuild.delete(projectPath);
12161216
// Do nothing
12171217
continue;

src/testRunner/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"unittests/services/textChanges.ts",
108108
"unittests/services/transpile.ts",
109109
"unittests/tsbuild/amdModulesWithOut.ts",
110+
"unittests/tsbuild/configFileErrors.ts",
110111
"unittests/tsbuild/containerOnlyReferenced.ts",
111112
"unittests/tsbuild/demo.ts",
112113
"unittests/tsbuild/emitDeclarationOnly.ts",
@@ -116,7 +117,6 @@
116117
"unittests/tsbuild/inferredTypeFromTransitiveModule.ts",
117118
"unittests/tsbuild/javascriptProjectEmit.ts",
118119
"unittests/tsbuild/lateBoundSymbol.ts",
119-
"unittests/tsbuild/missingExtendedFile.ts",
120120
"unittests/tsbuild/moduleSpecifiers.ts",
121121
"unittests/tsbuild/noEmitOnError.ts",
122122
"unittests/tsbuild/outFile.ts",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
namespace ts {
2+
describe("unittests:: tsbuild:: configFileErrors:: when tsconfig extends the missing file", () => {
3+
verifyTsc({
4+
scenario: "configFileErrors",
5+
subScenario: "when tsconfig extends the missing file",
6+
fs: () => loadProjectFromDisk("tests/projects/missingExtendedConfig"),
7+
commandLineArgs: ["--b", "/src/tsconfig.json"],
8+
});
9+
});
10+
11+
describe("unittests:: tsbuild:: configFileErrors:: reports syntax errors in config file", () => {
12+
verifyTscIncrementalEdits({
13+
scenario: "configFileErrors",
14+
subScenario: "reports syntax errors in config file",
15+
fs: () => loadProjectFromFiles({
16+
"/src/a.ts": "export function foo() { }",
17+
"/src/b.ts": "export function bar() { }",
18+
"/src/tsconfig.json": Utils.dedent`
19+
{
20+
"compilerOptions": {
21+
"composite": true,
22+
},
23+
"files": [
24+
"a.ts"
25+
"b.ts"
26+
]
27+
}`
28+
}),
29+
commandLineArgs: ["--b", "/src/tsconfig.json"],
30+
incrementalScenarios: [
31+
{
32+
buildKind: BuildKind.IncrementalDtsUnchanged,
33+
modifyFs: fs => replaceText(fs, "/src/tsconfig.json", ",", `,
34+
"declaration": true,`),
35+
subScenario: "reports syntax errors after change to config file"
36+
},
37+
{
38+
buildKind: BuildKind.IncrementalDtsUnchanged,
39+
modifyFs: fs => appendText(fs, "/src/a.ts", "export function fooBar() { }"),
40+
subScenario: "reports syntax errors after change to ts file"
41+
},
42+
noChangeRun,
43+
{
44+
buildKind: BuildKind.IncrementalDtsChange,
45+
modifyFs: fs => fs.writeFileSync(
46+
"/src/tsconfig.json",
47+
JSON.stringify({
48+
compilerOptions: { composite: true, declaration: true },
49+
files: ["a.ts", "b.ts"]
50+
})
51+
),
52+
subScenario: "builds after fixing config file errors"
53+
},
54+
]
55+
});
56+
});
57+
}

src/testRunner/unittests/tsbuild/containerOnlyReferenced.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
namespace ts {
22
describe("unittests:: tsbuild:: when containerOnly project is referenced", () => {
3-
let projFs: vfs.FileSystem;
4-
before(() => {
5-
projFs = loadProjectFromDisk("tests/projects/containerOnlyReferenced");
6-
});
7-
8-
after(() => {
9-
projFs = undefined!; // Release the contents
10-
});
11-
123
verifyTscIncrementalEdits({
134
scenario: "containerOnlyReferenced",
145
subScenario: "verify that subsequent builds after initial build doesnt build anything",
15-
fs: () => projFs,
6+
fs: () => loadProjectFromDisk("tests/projects/containerOnlyReferenced"),
167
commandLineArgs: ["--b", "/src", "--verbose"],
178
incrementalScenarios: [noChangeRun]
189
});

src/testRunner/unittests/tsbuild/javascriptProjectEmit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ namespace ts {
212212
{
213213
"extends": "../tsconfig.base.json",
214214
"compilerOptions": {
215-
"outDir": null
215+
"outDir": null,
216216
"composite": true
217217
},
218218
"include": ["index.ts", "obj.json"]

src/testRunner/unittests/tsbuild/lateBoundSymbol.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
namespace ts {
22
describe("unittests:: tsbuild:: lateBoundSymbol:: interface is merged and contains late bound member", () => {
3-
let projFs: vfs.FileSystem;
4-
before(() => {
5-
projFs = loadProjectFromDisk("tests/projects/lateBoundSymbol");
6-
});
7-
after(() => {
8-
projFs = undefined!; // Release the contents
9-
});
10-
113
verifyTscIncrementalEdits({
124
subScenario: "interface is merged and contains late bound member",
13-
fs: () => projFs,
5+
fs: () => loadProjectFromDisk("tests/projects/lateBoundSymbol"),
146
scenario: "lateBoundSymbol",
157
commandLineArgs: ["--b", "/src/tsconfig.json", "--verbose"],
168
incrementalScenarios: [{

src/testRunner/unittests/tsbuild/missingExtendedFile.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/testRunner/unittests/tsbuild/noEmitOnError.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
namespace ts {
22
describe("unittests:: tsbuild - with noEmitOnError", () => {
3-
let projFs: vfs.FileSystem;
4-
before(() => {
5-
projFs = loadProjectFromDisk("tests/projects/noEmitOnError");
6-
});
7-
after(() => {
8-
projFs = undefined!;
9-
});
103
verifyTsc({
114
scenario: "noEmitOnError",
125
subScenario: "has empty files diagnostic when files is empty and no references are provided",
13-
fs: () => projFs,
6+
fs: () => loadProjectFromDisk("tests/projects/noEmitOnError"),
147
commandLineArgs: ["--b", "/src/tsconfig.json"],
158
});
169
});

src/testRunner/unittests/tsbuild/outFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ namespace ts {
453453

454454
function stripInternalOfThird(fs: vfs.FileSystem) {
455455
replaceText(fs, sources[project.third][source.config], `"declaration": true,`, `"declaration": true,
456-
"stripInternal": true`);
456+
"stripInternal": true,`);
457457
}
458458

459459
function stripInternalScenario(fs: vfs.FileSystem, removeCommentsDisabled?: boolean, jsDocStyle?: boolean) {

src/testRunner/unittests/tsbuild/resolveJsonModule.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,10 @@ export default hello.hello`);
7171
});
7272

7373
describe("unittests:: tsbuild:: with resolveJsonModule option on project importJsonFromProjectReference", () => {
74-
let projFs: vfs.FileSystem;
75-
before(() => {
76-
projFs = loadProjectFromDisk("tests/projects/importJsonFromProjectReference");
77-
});
78-
79-
after(() => {
80-
projFs = undefined!; // Release the contents
81-
});
82-
8374
verifyTscIncrementalEdits({
8475
scenario: "resolveJsonModule",
8576
subScenario: "importing json module from project reference",
86-
fs: () => projFs,
77+
fs: () => loadProjectFromDisk("tests/projects/importJsonFromProjectReference"),
8778
commandLineArgs: ["--b", "src/tsconfig.json", "--verbose"],
8879
incrementalScenarios: [noChangeRun]
8980
});

0 commit comments

Comments
 (0)