Skip to content

Commit d63d081

Browse files
authored
Mark allowArbitraryExtensions as affectsProgramStructure (#52437)
1 parent 5e8bf48 commit d63d081

File tree

3 files changed

+224
-1
lines changed

3 files changed

+224
-1
lines changed

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
12211221
{
12221222
name: "allowArbitraryExtensions",
12231223
type: "boolean",
1224-
affectsModuleResolution: true,
1224+
affectsProgramStructure: true,
12251225
category: Diagnostics.Modules,
12261226
description: Diagnostics.Enable_importing_files_with_any_extension_provided_a_declaration_file_is_present,
12271227
defaultValueDescription: false,

src/testRunner/unittests/tscWatch/programUpdates.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,48 @@ describe("unittests:: tsc-watch:: program updates", () => {
273273
]
274274
});
275275

276+
verifyTscWatch({
277+
scenario,
278+
subScenario: "Updates diagnostics when '--allowArbitraryExtensions' changes",
279+
commandLineArgs: ["-w", "-p", "/tsconfig.json"],
280+
sys: () => {
281+
const aTs: File = {
282+
path: "/a.ts",
283+
content: "import {} from './b.css'"
284+
};
285+
const bCssTs: File = {
286+
path: "/b.d.css.ts",
287+
content: "declare const style: string;"
288+
};
289+
const tsconfig: File = {
290+
path: "/tsconfig.json",
291+
content: JSON.stringify({
292+
compilerOptions: { allowArbitraryExtensions: true },
293+
files: ["/a.ts"],
294+
})
295+
};
296+
return createWatchedSystem([libFile, aTs, bCssTs, tsconfig]);
297+
},
298+
edits: [
299+
{
300+
caption: "Disable allowArbitraryExtensions",
301+
edit: sys => sys.modifyFile("/tsconfig.json", JSON.stringify({
302+
compilerOptions: { allowArbitraryExtensions: false },
303+
files: ["/a.ts"],
304+
})),
305+
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1)
306+
},
307+
{
308+
caption: "Enable allowArbitraryExtensions",
309+
edit: sys => sys.modifyFile("/tsconfig.json", JSON.stringify({
310+
compilerOptions: { allowArbitraryExtensions: true },
311+
files: ["/a.ts"],
312+
})),
313+
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1),
314+
}
315+
]
316+
});
317+
276318
verifyTscWatch({
277319
scenario,
278320
subScenario: "updates diagnostics and emit for decorators",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
Input::
2+
//// [/a/lib/lib.d.ts]
3+
/// <reference no-default-lib="true"/>
4+
interface Boolean {}
5+
interface Function {}
6+
interface CallableFunction {}
7+
interface NewableFunction {}
8+
interface IArguments {}
9+
interface Number { toExponential: any; }
10+
interface Object {}
11+
interface RegExp {}
12+
interface String { charAt: any; }
13+
interface Array<T> { length: number; [n: number]: T; }
14+
15+
//// [/a.ts]
16+
import {} from './b.css'
17+
18+
//// [/b.d.css.ts]
19+
declare const style: string;
20+
21+
//// [/tsconfig.json]
22+
{"compilerOptions":{"allowArbitraryExtensions":true},"files":["/a.ts"]}
23+
24+
25+
/a/lib/tsc.js -w -p /tsconfig.json
26+
Output::
27+
>> Screen clear
28+
[12:00:15 AM] Starting compilation in watch mode...
29+
30+
a.ts:1:16 - error TS2306: File '/b.d.css.ts' is not a module.
31+
32+
1 import {} from './b.css'
33+
   ~~~~~~~~~
34+
35+
[12:00:18 AM] Found 1 error. Watching for file changes.
36+
37+
38+
39+
Program root files: ["/a.ts"]
40+
Program options: {"allowArbitraryExtensions":true,"watch":true,"project":"/tsconfig.json","configFilePath":"/tsconfig.json"}
41+
Program structureReused: Not
42+
Program files::
43+
/a/lib/lib.d.ts
44+
/b.d.css.ts
45+
/a.ts
46+
47+
Semantic diagnostics in builder refreshed for::
48+
/a/lib/lib.d.ts
49+
/b.d.css.ts
50+
/a.ts
51+
52+
Shape signatures in builder refreshed for::
53+
/a/lib/lib.d.ts (used version)
54+
/b.d.css.ts (used version)
55+
/a.ts (used version)
56+
57+
PolledWatches::
58+
59+
FsWatches::
60+
/tsconfig.json:
61+
{}
62+
/a.ts:
63+
{}
64+
/b.d.css.ts:
65+
{}
66+
/a/lib/lib.d.ts:
67+
{}
68+
69+
FsWatchesRecursive::
70+
71+
exitCode:: ExitStatus.undefined
72+
73+
//// [/a.js]
74+
"use strict";
75+
Object.defineProperty(exports, "__esModule", { value: true });
76+
77+
78+
79+
Change:: Disable allowArbitraryExtensions
80+
81+
Input::
82+
//// [/tsconfig.json]
83+
{"compilerOptions":{"allowArbitraryExtensions":false},"files":["/a.ts"]}
84+
85+
86+
Output::
87+
>> Screen clear
88+
[12:00:21 AM] File change detected. Starting incremental compilation...
89+
90+
a.ts:1:16 - error TS6263: Module './b.css' was resolved to '/b.d.css.ts', but '--allowArbitraryExtensions' is not set.
91+
92+
1 import {} from './b.css'
93+
   ~~~~~~~~~
94+
95+
[12:00:25 AM] Found 1 error. Watching for file changes.
96+
97+
98+
99+
Program root files: ["/a.ts"]
100+
Program options: {"allowArbitraryExtensions":false,"watch":true,"project":"/tsconfig.json","configFilePath":"/tsconfig.json"}
101+
Program structureReused: SafeModules
102+
Program files::
103+
/a/lib/lib.d.ts
104+
/a.ts
105+
106+
Semantic diagnostics in builder refreshed for::
107+
/a.ts
108+
109+
Shape signatures in builder refreshed for::
110+
/a.ts (computed .d.ts)
111+
112+
PolledWatches::
113+
114+
FsWatches::
115+
/tsconfig.json:
116+
{}
117+
/a.ts:
118+
{}
119+
/a/lib/lib.d.ts:
120+
{}
121+
122+
FsWatchesRecursive::
123+
124+
exitCode:: ExitStatus.undefined
125+
126+
//// [/a.js] file written with same contents
127+
128+
Change:: Enable allowArbitraryExtensions
129+
130+
Input::
131+
//// [/tsconfig.json]
132+
{"compilerOptions":{"allowArbitraryExtensions":true},"files":["/a.ts"]}
133+
134+
135+
Output::
136+
>> Screen clear
137+
[12:00:28 AM] File change detected. Starting incremental compilation...
138+
139+
a.ts:1:16 - error TS2306: File '/b.d.css.ts' is not a module.
140+
141+
1 import {} from './b.css'
142+
   ~~~~~~~~~
143+
144+
[12:00:32 AM] Found 1 error. Watching for file changes.
145+
146+
147+
148+
Program root files: ["/a.ts"]
149+
Program options: {"allowArbitraryExtensions":true,"watch":true,"project":"/tsconfig.json","configFilePath":"/tsconfig.json"}
150+
Program structureReused: SafeModules
151+
Program files::
152+
/a/lib/lib.d.ts
153+
/b.d.css.ts
154+
/a.ts
155+
156+
Semantic diagnostics in builder refreshed for::
157+
/a/lib/lib.d.ts
158+
/b.d.css.ts
159+
/a.ts
160+
161+
Shape signatures in builder refreshed for::
162+
/b.d.css.ts (used version)
163+
/a.ts (computed .d.ts)
164+
165+
PolledWatches::
166+
167+
FsWatches::
168+
/tsconfig.json:
169+
{}
170+
/a.ts:
171+
{}
172+
/a/lib/lib.d.ts:
173+
{}
174+
/b.d.css.ts:
175+
{}
176+
177+
FsWatchesRecursive::
178+
179+
exitCode:: ExitStatus.undefined
180+
181+
//// [/a.js] file written with same contents

0 commit comments

Comments
 (0)