Skip to content

Commit dfaf009

Browse files
committed
Forbid empty type argument/parameter list in babel-ts parser
1 parent 9765f19 commit dfaf009

File tree

3 files changed

+141
-4
lines changed

3 files changed

+141
-4
lines changed

src/language-js/parse/babel.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ const allowedReasonCodes = new Set([
182182
"StrictFunction",
183183
"ForInOfLoopInitializer",
184184

185-
"EmptyTypeArguments",
186-
"EmptyTypeParameters",
187185
"ConstructorHasTypeParameters",
188186

189187
"UnsupportedParameterPropertyKind",

tests/format/misc/errors/typescript/empty-type-arguments-parameters/__snapshots__/format.test.js.snap

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,278 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3+
exports[`snippet: #0 [babel-ts] format 1`] = `
4+
"Type argument list cannot be empty. (1:4)
5+
> 1 | foo<>()
6+
| ^
7+
Cause: Type argument list cannot be empty. (1:3)"
8+
`;
9+
310
exports[`snippet: #0 [typescript] format 1`] = `
411
"Type argument list cannot be empty. (1:4)
512
> 1 | foo<>()
613
| ^^
714
Cause: Type argument list cannot be empty."
815
`;
916

17+
exports[`snippet: #1 [babel-ts] format 1`] = `
18+
"Type argument list cannot be empty. (1:5)
19+
> 1 | (foo<>())
20+
| ^
21+
Cause: Type argument list cannot be empty. (1:4)"
22+
`;
23+
1024
exports[`snippet: #1 [typescript] format 1`] = `
1125
"Type argument list cannot be empty. (1:5)
1226
> 1 | (foo<>())
1327
| ^^
1428
Cause: Type argument list cannot be empty."
1529
`;
1630

31+
exports[`snippet: #2 [babel-ts] format 1`] = `
32+
"Type argument list cannot be empty. (1:8)
33+
> 1 | new Foo<>()
34+
| ^
35+
Cause: Type argument list cannot be empty. (1:7)"
36+
`;
37+
1738
exports[`snippet: #2 [typescript] format 1`] = `
1839
"Type argument list cannot be empty. (1:8)
1940
> 1 | new Foo<>()
2041
| ^^
2142
Cause: Type argument list cannot be empty."
2243
`;
2344

45+
exports[`snippet: #3 [babel-ts] format 1`] = `
46+
"Type parameter list cannot be empty. (1:13)
47+
> 1 | function foo<>(){}
48+
| ^
49+
Cause: Type parameter list cannot be empty. (1:12)"
50+
`;
51+
2452
exports[`snippet: #3 [typescript] format 1`] = `
2553
"Type parameter list cannot be empty. (1:13)
2654
> 1 | function foo<>(){}
2755
| ^^
2856
Cause: Type parameter list cannot be empty."
2957
`;
3058

59+
exports[`snippet: #4 [babel-ts] format 1`] = `
60+
"Type parameter list cannot be empty. (1:14)
61+
> 1 | (function foo<>(){})
62+
| ^
63+
Cause: Type parameter list cannot be empty. (1:13)"
64+
`;
65+
3166
exports[`snippet: #4 [typescript] format 1`] = `
3267
"Type parameter list cannot be empty. (1:14)
3368
> 1 | (function foo<>(){})
3469
| ^^
3570
Cause: Type parameter list cannot be empty."
3671
`;
3772

73+
exports[`snippet: #5 [babel-ts] format 1`] = `
74+
"Type parameter list cannot be empty. (1:10)
75+
> 1 | class Foo<> {}
76+
| ^
77+
Cause: Type parameter list cannot be empty. (1:9)"
78+
`;
79+
3880
exports[`snippet: #5 [typescript] format 1`] = `
3981
"Type parameter list cannot be empty. (1:10)
4082
> 1 | class Foo<> {}
4183
| ^^
4284
Cause: Type parameter list cannot be empty."
4385
`;
4486

87+
exports[`snippet: #6 [babel-ts] format 1`] = `
88+
"Type parameter list cannot be empty. (1:11)
89+
> 1 | (class Foo<> {})
90+
| ^
91+
Cause: Type parameter list cannot be empty. (1:10)"
92+
`;
93+
4594
exports[`snippet: #6 [typescript] format 1`] = `
4695
"Type parameter list cannot be empty. (1:11)
4796
> 1 | (class Foo<> {})
4897
| ^^
4998
Cause: Type parameter list cannot be empty."
5099
`;
51100

101+
exports[`snippet: #7 [babel-ts] format 1`] = `
102+
"Type parameter list cannot be empty. (1:23)
103+
> 1 | class Foo {constructor<>()}
104+
| ^
105+
Cause: Type parameter list cannot be empty. (1:22)"
106+
`;
107+
52108
exports[`snippet: #7 [typescript] format 1`] = `
53109
"Type parameter list cannot be empty. (1:23)
54110
> 1 | class Foo {constructor<>()}
55111
| ^^
56112
Cause: Type parameter list cannot be empty."
57113
`;
58114

115+
exports[`snippet: #8 [babel-ts] format 1`] = `
116+
"Type parameter list cannot be empty. (1:24)
117+
> 1 | (class Foo {constructor<>()})
118+
| ^
119+
Cause: Type parameter list cannot be empty. (1:23)"
120+
`;
121+
59122
exports[`snippet: #8 [typescript] format 1`] = `
60123
"Type parameter list cannot be empty. (1:24)
61124
> 1 | (class Foo {constructor<>()})
62125
| ^^
63126
Cause: Type parameter list cannot be empty."
64127
`;
65128

129+
exports[`snippet: #9 [babel-ts] format 1`] = `
130+
"Type parameter list cannot be empty. (1:18)
131+
> 1 | class Foo {method<>()}
132+
| ^
133+
Cause: Type parameter list cannot be empty. (1:17)"
134+
`;
135+
66136
exports[`snippet: #9 [typescript] format 1`] = `
67137
"Type parameter list cannot be empty. (1:18)
68138
> 1 | class Foo {method<>()}
69139
| ^^
70140
Cause: Type parameter list cannot be empty."
71141
`;
72142

143+
exports[`snippet: #10 [babel-ts] format 1`] = `
144+
"Type parameter list cannot be empty. (1:19)
145+
> 1 | (class Foo {method<>()})
146+
| ^
147+
Cause: Type parameter list cannot be empty. (1:18)"
148+
`;
149+
73150
exports[`snippet: #10 [typescript] format 1`] = `
74151
"Type parameter list cannot be empty. (1:19)
75152
> 1 | (class Foo {method<>()})
76153
| ^^
77154
Cause: Type parameter list cannot be empty."
78155
`;
79156

157+
exports[`snippet: #11 [babel-ts] format 1`] = `
158+
"Type parameter list cannot be empty. (1:22)
159+
> 1 | class Foo {get getter<>()}
160+
| ^
161+
Cause: Type parameter list cannot be empty. (1:21)"
162+
`;
163+
80164
exports[`snippet: #11 [typescript] format 1`] = `
81165
"Type parameter list cannot be empty. (1:22)
82166
> 1 | class Foo {get getter<>()}
83167
| ^^
84168
Cause: Type parameter list cannot be empty."
85169
`;
86170

171+
exports[`snippet: #12 [babel-ts] format 1`] = `
172+
"Type parameter list cannot be empty. (1:23)
173+
> 1 | (class Foo {get getter<>()})
174+
| ^
175+
Cause: Type parameter list cannot be empty. (1:22)"
176+
`;
177+
87178
exports[`snippet: #12 [typescript] format 1`] = `
88179
"Type parameter list cannot be empty. (1:23)
89180
> 1 | (class Foo {get getter<>()})
90181
| ^^
91182
Cause: Type parameter list cannot be empty."
92183
`;
93184

185+
exports[`snippet: #13 [babel-ts] format 1`] = `
186+
"Type argument list cannot be empty. (1:25)
187+
> 1 | class Foo {property: Bar<> = 1}
188+
| ^
189+
Cause: Type argument list cannot be empty. (1:24)"
190+
`;
191+
94192
exports[`snippet: #13 [typescript] format 1`] = `
95193
"Type argument list cannot be empty. (1:25)
96194
> 1 | class Foo {property: Bar<> = 1}
97195
| ^^
98196
Cause: Type argument list cannot be empty."
99197
`;
100198

199+
exports[`snippet: #14 [babel-ts] format 1`] = `
200+
"Type argument list cannot be empty. (1:26)
201+
> 1 | (class Foo {property: Bar<> = 1})
202+
| ^
203+
Cause: Type argument list cannot be empty. (1:25)"
204+
`;
205+
101206
exports[`snippet: #14 [typescript] format 1`] = `
102207
"Type argument list cannot be empty. (1:26)
103208
> 1 | (class Foo {property: Bar<> = 1})
104209
| ^^
105210
Cause: Type argument list cannot be empty."
106211
`;
107212

213+
exports[`snippet: #15 [babel-ts] format 1`] = `
214+
"Type parameter list cannot be empty. (1:14)
215+
> 1 | interface Foo<> {}
216+
| ^
217+
Cause: Type parameter list cannot be empty. (1:13)"
218+
`;
219+
108220
exports[`snippet: #15 [typescript] format 1`] = `
109221
"Type parameter list cannot be empty. (1:14)
110222
> 1 | interface Foo<> {}
111223
| ^^
112224
Cause: Type parameter list cannot be empty."
113225
`;
114226

227+
exports[`snippet: #16 [babel-ts] format 1`] = `
228+
"Type parameter list cannot be empty. (1:19)
229+
> 1 | interface Foo {bar<>()}
230+
| ^
231+
Cause: Type parameter list cannot be empty. (1:18)"
232+
`;
233+
115234
exports[`snippet: #16 [typescript] format 1`] = `
116235
"Type parameter list cannot be empty. (1:19)
117236
> 1 | interface Foo {bar<>()}
118237
| ^^
119238
Cause: Type parameter list cannot be empty."
120239
`;
121240

241+
exports[`snippet: #17 [babel-ts] format 1`] = `
242+
"Type parameter list cannot be empty. (1:16)
243+
> 1 | interface Foo {<>(): boolean}
244+
| ^
245+
Cause: Type parameter list cannot be empty. (1:15)"
246+
`;
247+
122248
exports[`snippet: #17 [typescript] format 1`] = `
123249
"Type parameter list cannot be empty. (1:16)
124250
> 1 | interface Foo {<>(): boolean}
125251
| ^^
126252
Cause: Type parameter list cannot be empty."
127253
`;
128254

255+
exports[`snippet: #18 [babel-ts] format 1`] = `
256+
"Type argument list cannot be empty. (1:15)
257+
> 1 | const foo: Foo<> = 1
258+
| ^
259+
Cause: Type argument list cannot be empty. (1:14)"
260+
`;
261+
129262
exports[`snippet: #18 [typescript] format 1`] = `
130263
"Type argument list cannot be empty. (1:15)
131264
> 1 | const foo: Foo<> = 1
132265
| ^^
133266
Cause: Type argument list cannot be empty."
134267
`;
135268

269+
exports[`snippet: #19 [babel-ts] format 1`] = `
270+
"Type parameter list cannot be empty. (1:12)
271+
> 1 | type Foo = <>() => {}
272+
| ^
273+
Cause: Type parameter list cannot be empty. (1:11)"
274+
`;
275+
136276
exports[`snippet: #19 [typescript] format 1`] = `
137277
"Type parameter list cannot be empty. (1:12)
138278
> 1 | type Foo = <>() => {}

tests/format/misc/errors/typescript/empty-type-arguments-parameters/format.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ runFormatTest(
2626
},
2727
[
2828
"typescript",
29-
// TODO[@fisker]: Unable on these parsers
30-
//"babel-ts",
29+
"babel-ts",
3130
// "oxc-ts",
3231
],
3332
);

0 commit comments

Comments
 (0)