8000 Add mroe incremental-affecting affixes to compiler options, add incre… · orta/TypeScript@8493ee8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8493ee8

Browse files
committed
Add mroe incremental-affecting affixes to compiler options, add incremental test for changing jsxImportSource
1 parent fe3b343 commit 8493ee8

File tree

4 files changed

+563
-0
lines changed

4 files changed

+563
-0
lines changed

src/compiler/commandLineParser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,8 @@ namespace ts {
803803
{
804804
name: "jsxImportSource",
805805
type: "string",
806+
affectsSemanticDiagnostics: true,
807+
affectsEmit: true,
806808
affectsModuleResolution: true,
807809
category: Diagnostics.Advanced_Options,
808810
description: Diagnostics.Specify_the_module_specifier_to_be_used_to_import_the_jsx_and_jsxs_factory_functions_from_eg_react

src/testRunner/unittests/tscWatch/incremental.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,5 +276,33 @@ export interface A {
276276
],
277277
modifyFs: host => host.deleteFile(`${project}/globals.d.ts`)
278278
});
279+
280+
const jsxImportSourceOptions = { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react" };
281+
const jsxLibraryContent = `export namespace JSX {
282+
interface Element {}
283+
interface IntrinsicElements {
284+
div: {
285+
propA?: boolean;
286+
};
287+
}
288+
}
289+
export function jsx(...args: any[]): void;
290+
export function jsxs(...args: any[]): void;
291+
export const Fragment: unique symbol;
292+
`;
293+
294+
verifyIncrementalWatchEmit({
295+
subScenario: "jsxImportSource option changed",
296+
files: () => [
297+
{ path: libFile.path, content: libContent },
298+
{ path: `${project}/node_modules/react/jsx-runtime/index.d.ts`, content: jsxLibraryContent },
299+
{ path: `${project}/node_modules/react/package.json`, content: JSON.stringify({ name: "react", version: "0.0.1" }) },
300+
{ path: `${project}/node_modules/preact/jsx-runtime/index.d.ts`, content: jsxLibraryContent.replace("propA", "propB") },
301+
{ path: `${project}/node_modules/preact/package.json`, content: JSON.stringify({ name: "preact", version: "0.0.1" }) },
302+
{ path: `${project}/index.tsx`, content: `export const App = () => <div propA={true}></div>;` },
303+
{ path: configFile.path, content: JSON.stringify({ compilerOptions: jsxImportSourceOptions }) }
304+
],
305+
modifyFs: host => host.writeFile(configFile.path, JSON.stringify({ compilerOptions: { ...jsxImportSourceOptions, jsxImportSource: "preact" } }))
306+
});
279307
});
280308
}
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
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+
interface ReadonlyArray<T> {}
15+
declare const console: { log(msg: any): void; };
16+
17+
//// [/users/username/projects/project/node_modules/react/jsx-runtime/index.d.ts]
18+
export namespace JSX {
19+
interface Element {}
20+
interface IntrinsicElements {
21+
div: {
22+
propA?: boolean;
23+
};
24+
}
25+
}
26+
export function jsx(...args: any[]): void;
27+
export function jsxs(...args: any[]): void;
28+
export const Fragment: unique symbol;
29+
30+
31+
//// [/users/username/projects/project/node_modules/react/package.json]
32+
{"name":"react","version":"0.0.1"}
33+
34+
//// [/users/username/projects/project/node_modules/preact/jsx-runtime/index.d.ts]
35+
export namespace JSX {
36+
interface Element {}
37+
interface IntrinsicElements {
38+
div: {
39+
propB?: boolean;
40+
};
41+
}
42+
}
43+
export function jsx(...args: any[]): void;
44+
export function jsxs(...args: any[]): void;
45+
export const Fragment: unique symbol;
46+
47+
48+
//// [/users/username/projects/project/node_modules/preact/package.json]
49+
{"name":"preact","version":"0.0.1"}
50+
51+
//// [/users/username/projects/project/index.tsx]
52+
export const App = () => <div propA={true}></div>;
53+
54+
//// [/users/username/projects/project/tsconfig.json]
55+
{"compilerOptions":{"module":"commonjs","jsx":"react-jsx","incremental":true,"jsxImportSource":"react"}}
56+
57+
58+
/a/lib/tsc.js -i
59+
Output::
60+
61+
62+
Program root files: ["/users/username/projects/project/index.tsx"]
63+
Program options: {"module":1,"jsx":4,"incremental":true,"jsxImportSource":"react","configFilePath":"/users/username/projects/project/tsconfig.json"}
64+
Program structureReused: Not
65+
Program files::
66+
/a/lib/lib.d.ts
67+
/users/username/projects/project/index.tsx
68+
/users/username/projects/project/node_modules/react/jsx-runtime/index.d.ts
69+
70+
Semantic diagnostics in builder refreshed for::
71+
/a/lib/lib.d.ts
72+
/users/username/projects/project/index.tsx
73+
/users/username/projects/project/node_modules/react/jsx-runtime/index.d.ts
74+
75+
WatchedFiles::
76+
77+
FsWatches::
78+
79+
FsWatchesRecursive::
80+
81+
exitCode:: ExitStatus.Success
82+
83+
//// [/users/username/projects/project/index.js]
84+
"use strict";
85+
exports.__esModule = true;
86+
exports.App = void 0;
87+
var jsx_runtime_1 = require("react/jsx-runtime");
88+
var App = function () { return jsx_runtime_1.jsx("div", { propA: true }, void 0); };
89+
exports.App = App;
90+
91+
92+
//// [/users/username/projects/project/tsconfig.tsbuildinfo]
93+
{
94+
"program": {
95+
"fileInfos": {
96+
"../../../../a/lib/lib.d.ts": {
97+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
98+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
99+
"affectsGlobalScope": true
100+
},
101+
"./index.tsx": {
102+
"version": "-14760199789-export const App = () => <div propA={true}></div>;",
103+
"signature": "-17269688391-export declare const App: () => import(\"react/jsx-runtime\").JSX.Element;\n",
104+
"affectsGlobalScope": false
105+
},
106+
"./node_modules/react/jsx-runtime/index.d.ts": {
107+
"version": "-35656056833-export namespace JSX {\n interface Element {}\n interface IntrinsicElements {\n div: {\n propA?: boolean;\n };\n }\n}\nexport function jsx(...args: any[]): void;\nexport function jsxs(...args: any[]): void;\nexport const Fragment: unique symbol;\n",
108+
"signature": "-35656056833-export namespace JSX {\n interface Element {}\n interface IntrinsicElements {\n div: {\n propA?: boolean;\n };\n }\n}\nexport function jsx(...args: any[]): void;\nexport function jsxs(...args: any[]): void;\nexport const Fragment: unique symbol;\n",
109+
"affectsGlobalScope": false
110+
}
111+
},
112+
"options": {
113+
"module": 1,
114+
"jsx": 4,
115+
"incremental": true,
116+
"jsxImportSource": "react",
117+
"configFilePath": "./tsconfig.json"
118+
},
119+
"referencedMap": {},
120+
"exportedModulesMap": {
121+
"./index.tsx": [
122+
"./node_modules/react/jsx-runtime/index.d.ts"
123+
]
124+
},
125+
"semanticDiagnosticsPerFile": [
126+
"../../../../a/lib/lib.d.ts",
127+
"./index.tsx",
128+
"./node_modules/react/jsx-runtime/index.d.ts"
129+
]
130+
},
131+
"version": "FakeTSVersion"
132+
}
133+
134+
135+
Change::
136+
137+
Input::
138+
//// [/users/username/projects/project/tsconfig.json]
139+
{"compilerOptions":{"module":"commonjs","jsx":"react-jsx","incremental":true,"jsxImportSource":"preact"}}
140+
141+
142+
Output::
143+
index.tsx:1:31 - error TS2322: Type '{ propA: boolean; }' is not assignable to type '{ propB?: boolean; }'.
144+
Property 'propA' does not exist on type '{ propB?: boolean; }'. Did you mean 'propB'?
145+
146+
1 export const App = () => <div propA={true}></div>;
147+
   ~~~~~
148+
149+
150+
Found 1 error.
151+
152+
153+
154+
Program root files: ["/users/username/projects/project/index.tsx"]
155+
Program options: {"module":1,"jsx":4,"incremental":true,"jsxImportSource":"preact","configFilePath":"/users/username/projects/project/tsconfig.json"}
156+
Program structureReused: Not
157+
Program files::
158+
/a/lib/lib.d.ts
159+
/users/username/projects/project/index.tsx
160+
/users/username/projects/project/node_modules/preact/jsx-runtime/index.d.ts
161+
162+
Semantic diagnostics in builder refreshed for::
163+
/a/lib/lib.d.ts
164+
/users/username/projects/project/index.tsx
165+
/users/username/projects/project/node_modules/preact/jsx-runtime/index.d.ts
166+
167+
WatchedFiles::
168+
169+
FsWatches::
170+
171+
FsWatchesRecursive::
172+
173+
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
174+
175+
//// [/users/username/projects/project/index.js]
176+
"use strict";
177+
exports.__esModule = true;
178+
exports.App = void 0;
179+
var jsx_runtime_1 = require("preact/jsx-runtime");
180+
var App = function () { return jsx_runtime_1.jsx("div", { propA: true }, void 0); };
181+
exports.App = App;
182+
183+
184+
//// [/users/username/projects/project/tsconfig.tsbuildinfo]
185+
{
186+
"program": {
187+
"fileInfos": {
188+
"../../../../a/lib/lib.d.ts": {
189+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
190+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
191+
"affectsGlobalScope": true
192+
},
193+
"./index.tsx": {
194+
"version": "-14760199789-export const App = () => <div propA={true}></div>;",
195+
"signature": "-17269688391-export declare const App: () => import(\"react/jsx-runtime\").JSX.Element;\n",
196+
"affectsGlobalScope": false
197+
},
198+
"./node_modules/preact/jsx-runtime/index.d.ts": {
199+
"version": "-17896129664-export namespace JSX {\n interface Element {}\n interface IntrinsicElements {\n div: {\n propB?: boolean;\n };\n }\n}\nexport function jsx(...args: any[]): void;\nexport function jsxs(...args: any[]): void;\nexport const Fragment: unique symbol;\n",
200+
"signature": "-17896129664-export namespace JSX {\n interface Element {}\n interface IntrinsicElements {\n div: {\n propB?: boolean;\n };\n }\n}\nexport function jsx(...args: any[]): void;\nexport function jsxs(...args: any[]): void;\nexport const Fragment: unique symbol;\n",
201+
"affectsGlobalScope": false
202+
}
203+
},
204+
"options": {
205+
"module": 1,
206+
"jsx": 4,
207+
"incremental": true,
208+
"jsxImportSource": "preact",
209+
"configFilePath": "./tsconfig.json"
210+
},
211+
"referencedMap": {},
212+
"exportedModulesMap": {
213+
"./index.tsx": [
214+
"./node_modules/react/jsx-runtime/index.d.ts"
215+
]
216+
},
217+
"semanticDiagnosticsPerFile": [
218+
"../../../../a/lib/lib.d.ts",
219+
[
220+
"./index.tsx",
221+
[
222+
{
223+
"file": "./index.tsx",
224+
"start": 30,
225+
"length": 5,
226+
"code": 2322,
227+
"category": 1,
228+
"messageText": {
229+
"messageText": "Type '{ propA: boolean; }' is not assignable to type '{ propB?: boolean; }'.",
230+
"category": 1,
231+
"code": 2322,
232+
"next": [
233+
{
234+
"messageText": "Property 'propA' does not exist on type '{ propB?: boolean; }'. Did you mean 'propB'?",
235+
"category": 1,
236+
"code": 2551
237+
}
238+
]
239+
}
240+
}
241+
]
242+
],
243+
"./node_modules/preact/jsx-runtime/index.d.ts"
244+
]
245+
},
246+
"version": "FakeTSVersion"
247+
}
248+

0 commit comments

Comments
 (0)
0