Skip to content

Commit 444872f

Browse files
committed
tsc composite tests
1 parent 24a860d commit 444872f

9 files changed

+904
-1
lines changed

internal/checker/checker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14633,7 +14633,7 @@ func (c *Checker) resolveExternalModule(location *ast.Node, moduleReference stri
1463314633
}
1463414634

1463514635
var message *diagnostics.Message
14636-
if overrideHost != nil && overrideHost.Kind == ast.KindImportDeclaration && overrideHost.AsImportDeclaration().ImportClause.IsTypeOnly() {
14636+
if overrideHost != nil && overrideHost.Kind == ast.KindImportDeclaration && overrideHost.AsImportDeclaration().ImportClause != nil && overrideHost.AsImportDeclaration().ImportClause.IsTypeOnly() {
1463714637
message = diagnostics.Type_only_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute
1463814638
} else if overrideHost != nil && overrideHost.Kind == ast.KindImportType {
1463914639
message = diagnostics.Type_import_of_an_ECMAScript_module_from_a_CommonJS_module_must_have_a_resolution_mode_attribute

internal/execute/tsc_test.go

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,185 @@ func TestTscCommandline(t *testing.T) {
129129
}
130130
}
131131

132+
func TestTscComposite(t *testing.T) {
133+
t.Parallel()
134+
testCases := []*tscInput{
135+
{
136+
subScenario: "when setting composite false on command line",
137+
files: FileMap{
138+
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
139+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
140+
{
141+
"compilerOptions": {
142+
"target": "es5",
143+
"module": "commonjs",
144+
"composite": true,
145+
},
146+
"include": [
147+
"src/**/*.ts",
148+
],
149+
}`),
150+
},
151+
commandLineArgs: []string{"--composite", "false"},
152+
},
153+
{
154+
// !!! sheetal null is not reflected in final options
155+
subScenario: "when setting composite null on command line",
156+
files: FileMap{
157+
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
158+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
159+
{
160+
"compilerOptions": {
161+
"target": "es5",
162+
"module": "commonjs",
163+
"composite": true,
164+
},
165+
"include": [
166+
"src/**/*.ts",
167+
],
168+
}`),
169+
},
170+
commandLineArgs: []string{"--composite", "null"},
171+
},
172+
{
173+
subScenario: "when setting composite false on command line but has tsbuild info in config",
174+
files: FileMap{
175+
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
176+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
177+
{
178+
"compilerOptions": {
179+
"target": "es5",
180+
"module": "commonjs",
181+
"composite": true,
182+
"tsBuildInfoFile": "tsconfig.json.tsbuildinfo",
183+
},
184+
"include": [
185+
"src/**/*.ts",
186+
],
187+
}`),
188+
},
189+
commandLineArgs: []string{"--composite", "false"},
190+
},
191+
{
192+
subScenario: "when setting composite false on command line but has tsbuild info in config",
193+
files: FileMap{
194+
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
195+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
196+
{
197+
"compilerOptions": {
198+
"target": "es5",
199+
"module": "commonjs",
200+
"composite": true,
201+
"tsBuildInfoFile": "tsconfig.json.tsbuildinfo",
202+
},
203+
"include": [
204+
"src/**/*.ts",
205+
],
206+
}`),
207+
},
208+
commandLineArgs: []string{"--composite", "false"},
209+
},
210+
{
211+
subScenario: "when setting composite false and tsbuildinfo as null on command line but has tsbuild info in config",
212+
files: FileMap{
213+
"/home/src/workspaces/project/src/main.ts": "export const x = 10;",
214+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
215+
{
216+
"compilerOptions": {
217+
"target": "es5",
218+
"module": "commonjs",
219+
"composite": true,
220+
"tsBuildInfoFile": "tsconfig.json.tsbuildinfo",
221+
},
222+
"include": [
223+
"src/**/*.ts",
224+
],
225+
}`),
226+
},
227+
commandLineArgs: []string{"--composite", "false", "--tsBuildInfoFile", "null"},
228+
},
229+
{
230+
subScenario: "converting to modules",
231+
files: FileMap{
232+
"/home/src/workspaces/project/src/main.ts": "const x = 10;",
233+
"/home/src/workspaces/project/tsconfig.json": stringtestutil.Dedent(`
234+
{
235+
"compilerOptions": {
236+
"module": "none",
237+
"composite": true,
238+
},
239+
}`),
240+
},
241+
edits: []*tscEdit{
242+
{
243+
caption: "convert to modules",
244+
edit: func(sys *testSys) {
245+
sys.replaceFileText("/home/src/workspaces/project/tsconfig.json", "none", "es2015")
246+
},
247+
},
248+
},
249+
},
250+
{
251+
subScenario: "synthetic jsx import of ESM module from CJS module no crash no jsx element",
252+
files: FileMap{
253+
"/home/src/projects/project/src/main.ts": "export default 42;",
254+
"/home/src/projects/project/tsconfig.json": stringtestutil.Dedent(`
255+
{
256+
"compilerOptions": {
257+
"composite": true,
258+
"module": "Node16",
259+
"jsx": "react-jsx",
260+
"jsxImportSource": "solid-js",
261+
},
262+
}`),
263+
"/home/src/projects/project/node_modules/solid-js/package.json": stringtestutil.Dedent(`
264+
{
265+
"name": "solid-js",
266+
"type": "module"
267+
}
268+
`),
269+
"/home/src/projects/project/node_modules/solid-js/jsx-runtime.d.ts": stringtestutil.Dedent(`
270+
export namespace JSX {
271+
type IntrinsicElements = { div: {}; };
272+
}
273+
`),
274+
},
275+
cwd: "/home/src/projects/project",
276+
},
277+
{
278+
subScenario: "synthetic jsx import of ESM module from CJS module error on jsx element",
279+
files: FileMap{
280+
"/home/src/projects/project/src/main.tsx": "export default <div/>;",
281+
"/home/src/projects/project/tsconfig.json": stringtestutil.Dedent(`
282+
{
283+
"compilerOptions": {
284+
"composite": true,
285+
"module": "Node16",
286+
"jsx": "react-jsx",
287+
"jsxImportSource": "solid-js",
288+
},
289+
}`),
290+
"/home/src/projects/project/node_modules/solid-js/package.json": stringtestutil.Dedent(`
291+
{
292+
"name": "solid-js",
293+
"type": "module"
294+
}
295+
`),
296+
"/home/src/projects/project/node_modules/solid-js/jsx-runtime.d.ts": stringtestutil.Dedent(`
297+
export namespace JSX {
298+
type IntrinsicElements = { div: {}; };
299+
}
300+
`),
301+
},
302+
cwd: "/home/src/projects/project",
303+
},
304+
}
305+
306+
for _, testCase := range testCases {
307+
testCase.run(t, "composite")
308+
}
309+
}
310+
132311
func TestNoEmit(t *testing.T) {
133312
t.Parallel()
134313
(&tscInput{
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
currentDirectory::/home/src/workspaces/project
2+
useCaseSensitiveFileNames::true
3+
Input::
4+
//// [/home/src/workspaces/project/src/main.ts] *new*
5+
const x = 10;
6+
//// [/home/src/workspaces/project/tsconfig.json] *new*
7+
{
8+
"compilerOptions": {
9+
"module": "none",
10+
"composite": true,
11+
},
12+
}
13+
14+
tsgo
15+
ExitStatus:: Success
16+
Output::
17+
//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib*
18+
/// <reference no-default-lib="true"/>
19+
interface Boolean {}
20+
interface Function {}
21+
interface CallableFunction {}
22+
interface NewableFunction {}
23+
interface IArguments {}
24+
interface Number { toExponential: any; }
25+
interface Object {}
26+
interface RegExp {}
27+
interface String { charAt: any; }
28+
interface Array<T> { length: number; [n: number]: T; }
29+
interface ReadonlyArray<T> {}
30+
interface SymbolConstructor {
31+
(desc?: string | number): symbol;
32+
for(name: string): symbol;
33+
readonly toStringTag: symbol;
34+
}
35+
declare var Symbol: SymbolConstructor;
36+
interface Symbol {
37+
readonly [Symbol.toStringTag]: string;
38+
}
39+
declare const console: { log(msg: any): void; };
40+
//// [/home/src/workspaces/project/src/main.d.ts] *new*
41+
declare const x = 10;
42+
43+
//// [/home/src/workspaces/project/src/main.js] *new*
44+
const x = 10;
45+
46+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *new*
47+
{"version":"FakeTSVersion","root":[2],"fileNames":["lib.d.ts","./src/main.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4447ab8c90027f28bdaff9f2056779ce-const x = 10;","signature":"4be7af7f970696121f4f582a5d074177-declare const x = 10;\n","affectsGlobalScope":true,"impliedNodeFormat":1}],"options":{"composite":true},"latestChangedDtsFile":"./src/main.d.ts"}
48+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
49+
{
50+
"version": "FakeTSVersion",
51+
"root": [
52+
{
53+
"files": [
54+
"./src/main.ts"
55+
],
56+
"original": 2
57+
}
58+
],
59+
"fileNames": [
60+
"lib.d.ts",
61+
"./src/main.ts"
62+
],
63+
"fileInfos": [
64+
{
65+
"fileName": "lib.d.ts",
66+
"version": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
67+
"signature": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
68+
"affectsGlobalScope": true,
69+
"impliedNodeFormat": "CommonJS",
70+
"original": {
71+
"version": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
72+
"affectsGlobalScope": true,
73+
"impliedNodeFormat": 1
74+
}
75+
},
76+
{
77+
"fileName": "./src/main.ts",
78+
"version": "4447ab8c90027f28bdaff9f2056779ce-const x = 10;",
79+
"signature": "4be7af7f970696121f4f582a5d074177-declare const x = 10;\n",
80+
"affectsGlobalScope": true,
81+
"impliedNodeFormat": "CommonJS",
82+
"original": {
83+
"version": "4447ab8c90027f28bdaff9f2056779ce-const x = 10;",
84+
"signature": "4be7af7f970696121f4f582a5d074177-declare const x = 10;\n",
85+
"affectsGlobalScope": true,
86+
"impliedNodeFormat": 1
87+
}
88+
}
89+
],
90+
"options": {
91+
"composite": true
92+
},
93+
"latestChangedDtsFile": "./src/main.d.ts",
94+
"size": 1113
95+
}
96+
97+
tsconfig.json::
98+
SemanticDiagnostics::
99+
*refresh* /home/src/tslibs/TS/Lib/lib.d.ts
100+
*refresh* /home/src/workspaces/project/src/main.ts
101+
Signatures::
102+
(stored at emit) /home/src/workspaces/project/src/main.ts
103+
104+
105+
Edit [0]:: convert to modules
106+
//// [/home/src/workspaces/project/tsconfig.json] *modified*
107+
{
108+
"compilerOptions": {
109+
"module": "es2015",
110+
"composite": true,
111+
},
112+
}
113+
114+
tsgo
115+
ExitStatus:: Success
116+
Output::
117+
//// [/home/src/workspaces/project/src/main.js] *rewrite with same content*
118+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *modified*
119+
{"version":"FakeTSVersion","root":[2],"fileNames":["lib.d.ts","./src/main.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"4447ab8c90027f28bdaff9f2056779ce-const x = 10;","signature":"4be7af7f970696121f4f582a5d074177-declare const x = 10;\n","affectsGlobalScope":true,"impliedNodeFormat":1}],"options":{"composite":true,"module":5},"latestChangedDtsFile":"./src/main.d.ts"}
120+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *modified*
121+
{
122+
"version": "FakeTSVersion",
123+
"root": [
124+
{
125+
"files": [
126+
"./src/main.ts"
127+
],
128+
"original": 2
129+
}
130+
],
131+
"fileNames": [
132+
"lib.d.ts",
133+
"./src/main.ts"
134+
],
135+
"fileInfos": [
136+
{
137+
"fileName": "lib.d.ts",
138+
"version": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
139+
"signature": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
140+
"affectsGlobalScope": true,
141+
"impliedNodeFormat": "CommonJS",
142+
"original": {
143+
"version": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
144+
"affectsGlobalScope": true,
145+
"impliedNodeFormat": 1
146+
}
147+
},
148+
{
149+
"fileName": "./src/main.ts",
150+
"version": "4447ab8c90027f28bdaff9f2056779ce-const x = 10;",
151+
"signature": "4be7af7f970696121f4f582a5d074177-declare const x = 10;\n",
152+
"affectsGlobalScope": true,
153+
"impliedNodeFormat": "CommonJS",
154+
"original": {
155+
"version": "4447ab8c90027f28bdaff9f2056779ce-const x = 10;",
156+
"signature": "4be7af7f970696121f4f582a5d074177-declare const x = 10;\n",
157+
"affectsGlobalScope": true,
158+
"impliedNodeFormat": 1
159+
}
160+
}
161+
],
162+
"options": {
163+
"composite": true,
164+
"module": 5
165+
},
166+
"latestChangedDtsFile": "./src/main.d.ts",
167+
"size": 1124
168+
}
169+
170+
tsconfig.json::
171+
SemanticDiagnostics::
172+
Signatures::

0 commit comments

Comments
 (0)