Skip to content

Commit 98ab3a7

Browse files
authored
Fix tsc --watch crash on module augmentations when module resolution changes (#39604)
* Add failing test * Ensure source files are bound before analyzing them
1 parent f68a839 commit 98ab3a7

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed

src/compiler/builderState.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ namespace ts {
206206
const hasCalledUpdateShapeSignature = new Set<Path>();
207207
const useOldState = canReuseOldState(referencedMap, oldState);
208208

209+
// Ensure source files have parent pointers set
210+
newProgram.getTypeChecker();
211+
209212
// Create the reference map, and set the file infos
210213
for (const sourceFile of newProgram.getSourceFiles()) {
211214
const version = Debug.checkDefined(sourceFile.version, "Program intended to be used with Builder should have source files with versions set");

src/testRunner/unittests/tscWatch/programUpdates.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,26 @@ export class A {
481481
changes: emptyArray
482482
});
483483

484+
verifyTscWatch({
485+
scenario,
486+
subScenario: "change module to none",
487+
commandLineArgs: ["-w", "-p", configFilePath],
488+
sys: () => {
489+
const file1 = {
490+
path: "/a/b/f1.ts",
491+
content: "export {}\ndeclare global {}"
492+
};
493+
return createWatchedSystem([file1, libFile, configFile]);
494+
},
495+
changes: [{
496+
caption: "change `module` to 'none'",
497+
timeouts: checkSingleTimeoutQueueLengthAndRun,
498+
change: sys => {
499+
sys.writeFile(configFilePath, JSON.stringify({ compilerOptions: { module: "none" } }));
500+
}
501+
}]
502+
});
503+
484504
it("correctly migrate files between projects", () => {
485505
const file1 = {
486506
path: "/a/b/f1.ts",
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
Input::
2+
//// [/a/b/f1.ts]
3+
export {}
4+
declare global {}
5+
6+
//// [/a/lib/lib.d.ts]
7+
/// <reference no-default-lib="true"/>
8+
interface Boolean {}
9+
interface Function {}
10+
interface CallableFunction {}
11+
interface NewableFunction {}
12+
interface IArguments {}
13+
interface Number { toExponential: any; }
14+
interface Object {}
15+
interface RegExp {}
16+
interface String { charAt: any; }
17+
interface Array<T> { length: number; [n: number]: T; }
18+
19+
//// [/a/b/tsconfig.json]
20+
{}
21+
22+
23+
/a/lib/tsc.js -w -p /a/b/tsconfig.json
24+
Output::
25+
>> Screen clear
26+
[12:00:15 AM] Starting compilation in watch mode...
27+
28+
29+
[12:00:18 AM] Found 0 errors. Watching for file changes.
30+
31+
32+
33+
Program root files: ["/a/b/f1.ts"]
34+
Program options: {"watch":true,"project":"/a/b/tsconfig.json","configFilePath":"/a/b/tsconfig.json"}
35+
Program files::
36+
/a/lib/lib.d.ts
37+
/a/b/f1.ts
38+
39+
Semantic diagnostics in builder refreshed for::
40+
/a/lib/lib.d.ts
41+
/a/b/f1.ts
42+
43+
WatchedFiles::
44+
/a/b/tsconfig.json:
45+
{"fileName":"/a/b/tsconfig.json","pollingInterval":250}
46+
/a/b/f1.ts:
47+
{"fileName":"/a/b/f1.ts","pollingInterval":250}
48+
/a/lib/lib.d.ts:
49+
{"fileName":"/a/lib/lib.d.ts","pollingInterval":250}
50+
51+
FsWatches::
52+
53+
FsWatchesRecursive::
54+
/a/b/node_modules/@types:
55+
{"directoryName":"/a/b/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
56+
/a/b:
57+
{"directoryName":"/a/b","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
58+
59+
exitCode:: ExitStatus.undefined
60+
61+
//// [/a/b/f1.js]
62+
"use strict";
63+
exports.__esModule = true;
64+
65+
66+
67+
Change:: change `module` to 'none'
68+
69+
Input::
70+
//// [/a/b/tsconfig.json]
71+
{"compilerOptions":{"module":"none"}}
72+
73+
74+
Output::
75+
>> Screen clear
76+
[12:00:22 AM] File change detected. Starting incremental compilation...
77+
78+
79+
a/b/f1.ts:1:1 - error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.
80+
81+
1 export {}
82+
  ~~~~~~~~~
83+
84+
85+
[12:00:26 AM] Found 1 error. Watching for file changes.
86+
87+
88+
89+
Program root files: ["/a/b/f1.ts"]
90+
Program options: {"module":0,"watch":true,"project":"/a/b/tsconfig.json","configFilePath":"/a/b/tsconfig.json"}
91+
Program files::
92+
/a/lib/lib.d.ts
93+
/a/b/f1.ts
94+
95+
Semantic diagnostics in builder refreshed for::
96+
/a/lib/lib.d.ts
97+
/a/b/f1.ts
98+
99+
WatchedFiles::
100+
/a/b/tsconfig.json:
101+
{"fileName":"/a/b/tsconfig.json","pollingInterval":250}
102+
/a/b/f1.ts:
103+
{"fileName":"/a/b/f1.ts","pollingInterval":250}
104+
/a/lib/lib.d.ts:
105+
{"fileName":"/a/lib/lib.d.ts","pollingInterval":250}
106+
107+
FsWatches::
108+
109+
FsWatchesRecursive::
110+
/a/b:
111+
{"directoryName":"/a/b","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
112+
/a/b/node_modules/@types:
113+
{"directoryName":"/a/b/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
114+
115+
exitCode:: ExitStatus.undefined
116+
117+
//// [/a/b/f1.js] file written with same contents

0 commit comments

Comments
 (0)