Skip to content

Commit f220e62

Browse files
ajafffsheetalkamat
authored andcommitted
importsNotUsedAsValue affects semantic diagnostics (#36001)
* importsNotUsedAsValue affects semantic diagnostics * add tests
1 parent 81a942e commit f220e62

File tree

3 files changed

+279
-0
lines changed

3 files changed

+279
-0
lines changed

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ namespace ts {
480480
error: importsNotUsedAsValues.Error
481481
}),
482482
affectsEmit: true,
483+
affectsSemanticDiagnostics: true,
483484
category: Diagnostics.Advanced_Options,
484485
description: Diagnostics.Specify_emit_Slashchecking_behavior_for_imports_that_are_only_used_for_types
485486
},

src/testRunner/unittests/tscWatch/programUpdates.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,45 @@ foo().hello`
11211121
]
11221122
});
11231123

1124+
verifyTscWatch({
1125+
scenario,
1126+
subScenario: "updates errors and emit when importsNotUsedAsValues changes",
1127+
commandLineArgs: ["-w"],
1128+
sys: () => {
1129+
const aFile: File = {
1130+
path: `${projectRoot}/a.ts`,
1131+
content: `export class C {}`
1132+
};
1133+
const bFile: File = {
1134+
path: `${projectRoot}/b.ts`,
1135+
content: `import {C} from './a';
1136+
export function f(p: C) { return p; }`
1137+
};
1138+
const config: File = {
1139+
path: `${projectRoot}/tsconfig.json`,
1140+
content: JSON.stringify({ compilerOptions: {} })
1141+
};
1142+
return createWatchedSystem([aFile, bFile, config, libFile], { currentDirectory: projectRoot });
1143+
},
1144+
changes: [
1145+
sys => {
1146+
sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({ compilerOptions: { importsNotUsedAsValues: "remove" } }));
1147+
sys.runQueuedTimeoutCallbacks();
1148+
return 'Set to "remove"';
1149+
},
1150+
sys => {
1151+
sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({ compilerOptions: { importsNotUsedAsValues: "error" } }));
1152+
sys.runQueuedTimeoutCallbacks();
1153+
return 'Set to "error"';
1154+
},
1155+
sys => {
1156+
sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({ compilerOptions: { importsNotUsedAsValues: "preserve" } }));
1157+
sys.runQueuedTimeoutCallbacks();
1158+
return 'Set to "preserve"';
1159+
},
1160+
]
1161+
});
1162+
11241163
verifyTscWatch({
11251164
scenario,
11261165
subScenario: "updates errors when ambient modules of program changes",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
/a/lib/tsc.js -w
2+
//// [/user/username/projects/myproject/a.ts]
3+
export class C {}
4+
5+
//// [/user/username/projects/myproject/b.ts]
6+
import {C} from './a';
7+
export function f(p: C) { return p; }
8+
9+
//// [/user/username/projects/myproject/tsconfig.json]
10+
{"compilerOptions":{}}
11+
12+
//// [/a/lib/lib.d.ts]
13+
/// <reference no-default-lib="true"/>
14+
interface Boolean {}
15+
interface Function {}
16+
interface CallableFunction {}
17+
interface NewableFunction {}
18+
interface IArguments {}
19+
interface Number { toExponential: any; }
20+
interface Object {}
21+
interface RegExp {}
22+
interface String { charAt: any; }
23+
interface Array<T> { length: number; [n: number]: T; }
24+
25+
//// [/user/username/projects/myproject/a.js]
26+
"use strict";
27+
exports.__esModule = true;
28+
var C = /** @class */ (function () {
29+
function C() {
30+
}
31+
return C;
32+
}());
33+
exports.C = C;
34+
35+
36+
//// [/user/username/projects/myproject/b.js]
37+
"use strict";
38+
exports.__esModule = true;
39+
function f(p) { return p; }
40+
exports.f = f;
41+
42+
43+
44+
Output::
45+
>> Screen clear
46+
12:00:23 AM - Starting compilation in watch mode...
47+
48+
49+
50+
12:00:28 AM - Found 0 errors. Watching for file changes.
51+
52+
53+
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
54+
Program options: {"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
55+
Program files::
56+
/a/lib/lib.d.ts
57+
/user/username/projects/myproject/a.ts
58+
/user/username/projects/myproject/b.ts
59+
60+
Semantic diagnostics in builder refreshed for::
61+
/a/lib/lib.d.ts
62+
/user/username/projects/myproject/a.ts
63+
/user/username/projects/myproject/b.ts
64+
65+
WatchedFiles::
66+
/user/username/projects/myproject/tsconfig.json:
67+
{"pollingInterval":250}
68+
/user/username/projects/myproject/a.ts:
69+
{"pollingInterval":250}
70+
/user/username/projects/myproject/b.ts:
71+
{"pollingInterval":250}
72+
/a/lib/lib.d.ts:
73+
{"pollingInterval":250}
74+
75+
FsWatches::
76+
77+
FsWatchesRecursive::
78+
/user/username/projects/myproject/node_modules/@types:
79+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
80+
/user/username/projects/myproject:
81+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
82+
83+
exitCode:: ExitStatus.undefined
84+
85+
Change:: Set to "remove"
86+
87+
//// [/user/username/projects/myproject/tsconfig.json]
88+
{"compilerOptions":{"importsNotUsedAsValues":"remove"}}
89+
90+
//// [/user/username/projects/myproject/a.js] file written with same contents
91+
//// [/user/username/projects/myproject/b.js] file written with same contents
92+
93+
Output::
94+
>> Screen clear
95+
12:00:32 AM - File change detected. Starting incremental compilation...
96+
97+
98+
99+
12:00:39 AM - Found 0 errors. Watching for file changes.
100+
101+
102+
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
103+
Program options: {"importsNotUsedAsValues":0,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
104+
Program files::
105+
/a/lib/lib.d.ts
106+
/user/username/projects/myproject/a.ts
107+
/user/username/projects/myproject/b.ts
108+
109+
Semantic diagnostics in builder refreshed for::
110+
/a/lib/lib.d.ts
111+
/user/username/projects/myproject/a.ts
112+
/user/username/projects/myproject/b.ts
113+
114+
WatchedFiles::
115+
/user/username/projects/myproject/tsconfig.json:
116+
{"pollingInterval":250}
117+
/user/username/projects/myproject/a.ts:
118+
{"pollingInterval":250}
119+
/user/username/projects/myproject/b.ts:
120+
{"pollingInterval":250}
121+
/a/lib/lib.d.ts:
122+
{"pollingInterval":250}
123+
124+
FsWatches::
125+
126+
FsWatchesRecursive::
127+
/user/username/projects/myproject/node_modules/@types:
128+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
129+
/user/username/projects/myproject:
130+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
131+
132+
exitCode:: ExitStatus.undefined
133+
134+
Change:: Set to "error"
135+
136+
//// [/user/username/projects/myproject/tsconfig.json]
137+
{"compilerOptions":{"importsNotUsedAsValues":"error"}}
138+
139+
//// [/user/username/projects/myproject/a.js] file written with same contents
140+
//// [/user/username/projects/myproject/b.js]
141+
"use strict";
142+
exports.__esModule = true;
143+
require("./a");
144+
function f(p) { return p; }
145+
exports.f = f;
146+
147+
148+
149+
Output::
150+
>> Screen clear
151+
12:00:43 AM - File change detected. Starting incremental compilation...
152+
153+
154+
b.ts(1,1): error TS1371: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
155+
156+
157+
12:00:50 AM - Found 1 error. Watching for file changes.
158+
159+
160+
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
161+
Program options: {"importsNotUsedAsValues":2,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
162+
Program files::
163+
/a/lib/lib.d.ts
164+
/user/username/projects/myproject/a.ts
165+
/user/username/projects/myproject/b.ts
166+
167+
Semantic diagnostics in builder refreshed for::
168+
/a/lib/lib.d.ts
169+
/user/username/projects/myproject/a.ts
170+
/user/username/projects/myproject/b.ts
171+
172+
WatchedFiles::
173+
/user/username/projects/myproject/tsconfig.json:
174+
{"pollingInterval":250}
175+
/user/username/projects/myproject/a.ts:
176+
{"pollingInterval":250}
177+
/user/username/projects/myproject/b.ts:
178+
{"pollingInterval":250}
179+
/a/lib/lib.d.ts:
180+
{"pollingInterval":250}
181+
182+
FsWatches::
183+
184+
FsWatchesRecursive::
185+
/user/username/projects/myproject/node_modules/@types:
186+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
187+
/user/username/projects/myproject:
188+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
189+
190+
exitCode:: ExitStatus.undefined
191+
192+
Change:: Set to "preserve"
193+
194+
//// [/user/username/projects/myproject/tsconfig.json]
195+
{"compilerOptions":{"importsNotUsedAsValues":"preserve"}}
196+
197+
//// [/user/username/projects/myproject/a.js] file written with same contents
198+
//// [/user/username/projects/myproject/b.js] file written with same contents
199+
200+
Output::
201+
>> Screen clear
202+
12:00:54 AM - File change detected. Starting incremental compilation...
203+
204+
205+
206+
12:01:01 AM - Found 0 errors. Watching for file changes.
207+
208+
209+
Program root files: ["/user/username/projects/myproject/a.ts","/user/username/projects/myproject/b.ts"]
210+
Program options: {"importsNotUsedAsValues":1,"watch":true,"configFilePath":"/user/username/projects/myproject/tsconfig.json"}
211+
Program files::
212+
/a/lib/lib.d.ts
213+
/user/username/projects/myproject/a.ts
214+
/user/username/projects/myproject/b.ts
215+
216+
Semantic diagnostics in builder refreshed for::
217+
/a/lib/lib.d.ts
218+
/user/username/projects/myproject/a.ts
219+
/user/username/projects/myproject/b.ts
220+
221+
WatchedFiles::
222+
/user/username/projects/myproject/tsconfig.json:
223+
{"pollingInterval":250}
224+
/user/username/projects/myproject/a.ts:
225+
{"pollingInterval":250}
226+
/user/username/projects/myproject/b.ts:
227+
{"pollingInterval":250}
228+
/a/lib/lib.d.ts:
229+
{"pollingInterval":250}
230+
231+
FsWatches::
232+
233+
FsWatchesRecursive::
234+
/user/username/projects/myproject/node_modules/@types:
235+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
236+
/user/username/projects/myproject:
237+
{"fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
238+
239+
exitCode:: ExitStatus.undefined

0 commit comments

Comments
 (0)