Skip to content

Commit 21a6806

Browse files
committed
More refactoring
1 parent 70069d2 commit 21a6806

File tree

61 files changed

+514
-449
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+514
-449
lines changed

src/testRunner/unittests/tscWatch/emitAndErrorUpdates.ts

+64-59
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,88 @@ namespace ts.tscWatch {
44
path: `${projectRoot}/tsconfig.json`,
55
content: `{}`
66
};
7-
interface VerifyEmitAndErrorUpdatesWorker extends VerifyEmitAndErrorUpdates {
8-
configFile: () => File;
7+
interface VerifyEmitAndErrorUpdates {
8+
subScenario: string
9+
files: () => File[];
10+
currentDirectory?: string;
11+
changes: TscWatchCompileChange[];
912
}
10-
function verifyEmitAndErrorUpdatesWorker({
13+
function verifyEmitAndErrorUpdates({
1114
subScenario,
1215
files,
1316
currentDirectory,
14-
lib,
15-
configFile,
1617
changes,
17-
}: VerifyEmitAndErrorUpdatesWorker) {
18+
}: VerifyEmitAndErrorUpdates) {
1819
verifyTscWatch({
1920
scenario: "emitAndErrorUpdates",
20-
subScenario,
21+
subScenario: `default/${subScenario}`,
2122
commandLineArgs: ["--w"],
2223
sys: () => createWatchedSystem(
23-
[...files(), configFile(), lib?.() || libFile],
24+
files(),
2425
{ currentDirectory: currentDirectory || projectRoot }
2526
),
2627
changes,
2728
baselineIncremental: true
2829
});
29-
}
30-
31-
function changeCompilerOptions(input: VerifyEmitAndErrorUpdates, additionalOptions: CompilerOptions): File {
32-
const configFile = input.configFile?.() || config;
33-
const content = JSON.parse(configFile.content);
34-
content.compilerOptions = { ...content.compilerOptions, ...additionalOptions };
35-
return { path: configFile.path, content: JSON.stringify(content) };
36-
}
37-
38-
interface VerifyEmitAndErrorUpdates {
39-
subScenario: string
40-
files: () => File[];
41-
currentDirectory?: string;
42-
lib?: () => File;
43-
changes: TscWatchCompileChange[];
44-
configFile?: () => File;
45-
}
46-
function verifyEmitAndErrorUpdates(input: VerifyEmitAndErrorUpdates) {
47-
verifyEmitAndErrorUpdatesWorker({
48-
...input,
49-
subScenario: `default/${input.subScenario}`,
50-
configFile: () => input.configFile?.() || config
51-
});
5230

53-
verifyEmitAndErrorUpdatesWorker({
54-
...input,
55-
subScenario: `defaultAndD/${input.subScenario}`,
56-
configFile: () => changeCompilerOptions(input, { declaration: true })
31+
verifyTscWatch({
32+
scenario: "emitAndErrorUpdates",
33+
subScenario: `defaultAndD/${subScenario}`,
34+
commandLineArgs: ["--w", "--d"],
35+
sys: () => createWatchedSystem(
36+
files(),
37+
{ currentDirectory: currentDirectory || projectRoot }
38+
),
39+
changes,
40+
baselineIncremental: true
5741
});
5842

59-
verifyEmitAndErrorUpdatesWorker({
60-
...input,
61-
subScenario: `isolatedModules/${input.subScenario}`,
62-
configFile: () => changeCompilerOptions(input, { isolatedModules: true })
43+
verifyTscWatch({
44+
scenario: "emitAndErrorUpdates",
45+
subScenario: `isolatedModules/${subScenario}`,
46+
commandLineArgs: ["--w", "--isolatedModules"],
47+
sys: () => createWatchedSystem(
48+
files(),
49+
{ currentDirectory: currentDirectory || projectRoot }
50+
),
51+
changes,
52+
baselineIncremental: true
6353
});
6454

65-
verifyEmitAndErrorUpdatesWorker({
66-
...input,
67-
subScenario: `isolatedModulesAndD/${input.subScenario}`,
68-
configFile: () => changeCompilerOptions(input, { isolatedModules: true, declaration: true })
55+
verifyTscWatch({
56+
scenario: "emitAndErrorUpdates",
57+
subScenario: `isolatedModulesAndD/${subScenario}`,
58+
commandLineArgs: ["--w", "--isolatedModules", "--d"],
59+
sys: () => createWatchedSystem(
60+
files(),
61+
{ currentDirectory: currentDirectory || projectRoot }
62+
),
63+
changes,
64+
baselineIncremental: true
6965
});
7066

71-
verifyEmitAndErrorUpdatesWorker({
72-
...input,
73-
subScenario: `assumeChangesOnlyAffectDirectDependencies/${input.subScenario}`,
74-
configFile: () => changeCompilerOptions(input, { assumeChangesOnlyAffectDirectDependencies: true })
67+
verifyTscWatch({
68+
scenario: "emitAndErrorUpdates",
69+
subScenario: `assumeChangesOnlyAffectDirectDependencies/${subScenario}`,
70+
commandLineArgs: ["--w", "--assumeChangesOnlyAffectDirectDependencies"],
71+
sys: () => createWatchedSystem(
72+
files(),
73+
{ currentDirectory: currentDirectory || projectRoot }
74+
),
75+
changes,
76+
baselineIncremental: true
7577
});
7678

77-
verifyEmitAndErrorUpdatesWorker({
78-
...input,
79-
subScenario: `assumeChangesOnlyAffectDirectDependenciesAndD/${input.subScenario}`,
80-
configFile: () => changeCompilerOptions(input, { assumeChangesOnlyAffectDirectDependencies: true, declaration: true })
79+
verifyTscWatch({
80+
scenario: "emitAndErrorUpdates",
81+
subScenario: `assumeChangesOnlyAffectDirectDependenciesAndD/${subScenario}`,
82+
commandLineArgs: ["--w", "--assumeChangesOnlyAffectDirectDependencies", "--d"],
83+
sys: () => createWatchedSystem(
84+
files(),
85+
{ currentDirectory: currentDirectory || projectRoot }
86+
),
87+
changes,
88+
baselineIncremental: true
8189
});
8290
}
8391

@@ -93,7 +101,7 @@ console.log(b.c.d);`
93101
function verifyDeepImportChange(subScenario: string, bFile: File, cFile: File) {
94102
verifyEmitAndErrorUpdates({
95103
subScenario: `deepImportChanges/${subScenario}`,
96-
files: () => [aFile, bFile, cFile],
104+
files: () => [aFile, bFile, cFile, config, libFile],
97105
changes: [
98106
{
99107
caption: "Rename property d to d2 of class C to initialize signatures",
@@ -201,7 +209,7 @@ getPoint().c.x;`
201209
};
202210
verifyEmitAndErrorUpdates({
203211
subScenario: "file not exporting a deep multilevel import that changes",
204-
files: () => [aFile, bFile, cFile, dFile, eFile],
212+
files: () => [aFile, bFile, cFile, dFile, eFile, config, libFile],
205213
changes: [
206214
{
207215
caption: "Rename property x2 to x of interface Coords to initialize signatures",
@@ -272,8 +280,7 @@ export class Data {
272280
function verifyTransitiveExports(subScenario: string, files: readonly File[]) {
273281
verifyEmitAndErrorUpdates({
274282
subScenario: `transitive exports/${subScenario}`,
275-
files: () => [lib1ToolsInterface, lib1ToolsPublic, app, lib2Public, lib1Public, ...files],
276-
configFile: () => config,
283+
files: () => [lib1ToolsInterface, lib1ToolsPublic, app, lib2Public, lib1Public, ...files, config, libFile],
277284
changes: [
278285
{
279286
caption: "Rename property title to title2 of interface ITest to initialize signatures",
@@ -344,10 +351,8 @@ export class Data2 {
344351
verifyEmitAndErrorUpdates({
345352
subScenario: "with noEmitOnError",
346353
currentDirectory: `${TestFSWithWatch.tsbuildProjectsLocation}/noEmitOnError`,
347-
files: () => ["shared/types/db.ts", "src/main.ts", "src/other.ts"]
348-
.map(f => TestFSWithWatch.getTsBuildProjectFile("noEmitOnError", f)),
349-
lib: () => ({ path: libFile.path, content: libContent }),
350-
configFile: () => TestFSWithWatch.getTsBuildProjectFile("noEmitOnError", "tsconfig.json"),
354+
files: () => ["shared/types/db.ts", "src/main.ts", "src/other.ts", "tsconfig.json"]
355+
.map(f => TestFSWithWatch.getTsBuildProjectFile("noEmitOnError", f)).concat({ path: libFile.path, content: libContent }),
351356
changes: [
352357
noChange,
353358
change("Fix Syntax error", `import { A } from "../shared/types/db";

tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/deepImportChanges/errors-for-.d.ts-change-with-incremental.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class C
1919
}
2020

2121
//// [/user/username/projects/myproject/tsconfig.json]
22-
{"compilerOptions":{"assumeChangesOnlyAffectDirectDependencies":true}}
22+
{}
2323

2424
//// [/a/lib/lib.d.ts]
2525
/// <reference no-default-lib="true"/>
@@ -35,7 +35,7 @@ interface String { charAt: any; }
3535
interface Array<T> { length: number; [n: number]: T; }
3636

3737

38-
/a/lib/tsc.js --w --incremental
38+
/a/lib/tsc.js --w --assumeChangesOnlyAffectDirectDependencies --incremental
3939
Output::
4040
>> Screen clear
4141
[12:00:25 AM] Starting compilation in watch mode...
@@ -45,7 +45,7 @@ Output::
4545

4646

4747
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.d.ts","/user/username/projects/myproject/c.d.ts"]
48-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
48+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
4949
Program structureReused: Not
5050
Program files::
5151
/a/lib/lib.d.ts
@@ -186,7 +186,7 @@ Output::
186186

187187

188188
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.d.ts","/user/username/projects/myproject/c.d.ts"]
189-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
189+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
190190
Program structureReused: Completely
191191
Program files::
192192
/a/lib/lib.d.ts
@@ -315,7 +315,7 @@ Output::
315315

316316

317317
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.d.ts","/user/username/projects/myproject/c.d.ts"]
318-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
318+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
319319
Program structureReused: Completely
320320
Program files::
321321
/a/lib/lib.d.ts
@@ -444,7 +444,7 @@ Output::
444444

445445

446446
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.d.ts","/user/username/projects/myproject/c.d.ts"]
447-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
447+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
448448
Program structureReused: Completely
449449
Program files::
450450
/a/lib/lib.d.ts

tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/deepImportChanges/errors-for-.d.ts-change.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class C
1919
}
2020

2121
//// [/user/username/projects/myproject/tsconfig.json]
22-
{"compilerOptions":{"assumeChangesOnlyAffectDirectDependencies":true}}
22+
{}
2323

2424
//// [/a/lib/lib.d.ts]
2525
/// <reference no-default-lib="true"/>
@@ -35,7 +35,7 @@ interface String { charAt: any; }
3535
interface Array<T> { length: number; [n: number]: T; }
3636

3737

38-
/a/lib/tsc.js --w
38+
/a/lib/tsc.js --w --assumeChangesOnlyAffectDirectDependencies
3939
Output::
4040
>> Screen clear
4141
[12:00:25 AM] Starting compilation in watch mode...
@@ -45,7 +45,7 @@ Output::
4545

4646

4747
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.d.ts","/user/username/projects/myproject/c.d.ts"]
48-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
48+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
4949
Program structureReused: Not
5050
Program files::
5151
/a/lib/lib.d.ts
@@ -117,7 +117,7 @@ Output::
117117

118118

119119
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.d.ts","/user/username/projects/myproject/c.d.ts"]
120-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
120+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
121121
Program structureReused: Completely
122122
Program files::
123123
/a/lib/lib.d.ts
@@ -177,7 +177,7 @@ Output::
177177

178178

179179
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.d.ts","/user/username/projects/myproject/c.d.ts"]
180-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
180+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
181181
Program structureReused: Completely
182182
Program files::
183183
/a/lib/lib.d.ts
@@ -237,7 +237,7 @@ Output::
237237

238238

239239
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.d.ts","/user/username/projects/myproject/c.d.ts"]
240-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
240+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
241241
Program structureReused: Completely
242242
Program files::
243243
/a/lib/lib.d.ts

tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/deepImportChanges/errors-for-.ts-change-with-incremental.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class C
1919
}
2020

2121
//// [/user/username/projects/myproject/tsconfig.json]
22-
{"compilerOptions":{"assumeChangesOnlyAffectDirectDependencies":true}}
22+
{}
2323

2424
//// [/a/lib/lib.d.ts]
2525
/// <reference no-default-lib="true"/>
@@ -35,7 +35,7 @@ interface String { charAt: any; }
3535
interface Array<T> { length: number; [n: number]: T; }
3636

3737

38-
/a/lib/tsc.js --w --incremental
38+
/a/lib/tsc.js --w --assumeChangesOnlyAffectDirectDependencies --incremental
3939
Output::
4040
>> Screen clear
4141
[12:00:25 AM] Starting compilation in watch mode...
@@ -45,7 +45,7 @@ Output::
4545

4646

4747
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts","/user/username/projects/myproject/c.ts"]
48-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
48+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
4949
Program structureReused: Not
5050
Program files::
5151
/a/lib/lib.d.ts
@@ -216,7 +216,7 @@ Output::
216216

217217

218218
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts","/user/username/projects/myproject/c.ts"]
219-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
219+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
220220
Program structureReused: Completely
221221
Program files::
222222
/a/lib/lib.d.ts
@@ -374,7 +374,7 @@ Output::
374374

375375

376376
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts","/user/username/projects/myproject/c.ts"]
377-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
377+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
378378
Program structureReused: Completely
379379
Program files::
380380
/a/lib/lib.d.ts
@@ -529,7 +529,7 @@ Output::
529529

530530

531531
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts","/user/username/projects/myproject/c.ts"]
532-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
532+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"incremental":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
533533
Program structureReused: Completely
534534
Program files::
535535
/a/lib/lib.d.ts

tests/baselines/reference/tscWatch/emitAndErrorUpdates/assumeChangesOnlyAffectDirectDependencies/deepImportChanges/errors-for-.ts-change.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class C
1919
}
2020

2121
//// [/user/username/projects/myproject/tsconfig.json]
22-
{"compilerOptions":{"assumeChangesOnlyAffectDirectDependencies":true}}
22+
{}
2323

2424
//// [/a/lib/lib.d.ts]
2525
/// <reference no-default-lib="true"/>
@@ -35,7 +35,7 @@ interface String { charAt: any; }
3535
interface Array<T> { length: number; [n: number]: T; }
3636

3737

38-
/a/lib/tsc.js --w
38+
/a/lib/tsc.js --w --assumeChangesOnlyAffectDirectDependencies
3939
Output::
4040
>> Screen clear
4141
[12:00:25 AM] Starting compilation in watch mode...
@@ -45,7 +45,7 @@ Output::
4545

4646

4747
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts","/user/username/projects/myproject/c.ts"]
48-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
48+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
4949
Program structureReused: Not
5050
Program files::
5151
/a/lib/lib.d.ts
@@ -147,7 +147,7 @@ Output::
147147

148148

149149
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts","/user/username/projects/myproject/c.ts"]
150-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
150+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
151151
Program structureReused: Completely
152152
Program files::
153153
/a/lib/lib.d.ts
@@ -227,7 +227,7 @@ Output::
227227

228228

229229
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts","/user/username/projects/myproject/c.ts"]
230-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
230+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
231231
Program structureReused: Completely
232232
Program files::
233233
/a/lib/lib.d.ts
@@ -304,7 +304,7 @@ Output::
304304

305305

306306
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts","/user/username/projects/myproject/c.ts"]
307-
Program options: {"assumeChangesOnlyAffectDirectDependencies":true,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
307+
Program options: {"watch":true,"assumeChangesOnlyAffectDirectDependencies":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
308308
Program structureReused: Completely
309309
Program files::
310310
/a/lib/lib.d.ts

0 commit comments

Comments
 (0)