Skip to content

Commit 9082e68

Browse files
Parse arrows with params annotations in conditional expressions (#10669)
1 parent bdb4318 commit 9082e68

5 files changed

Lines changed: 476 additions & 0 deletions

File tree

packages/babel-parser/src/plugins/flow.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
20612061
return node.operator === "=";
20622062

20632063
case "ParenthesizedExpression":
2064+
case "TypeCastExpression":
20642065
return this.isAssignable(node.expression);
20652066

20662067
case "MemberExpression":
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test
2+
? (x: T): U => y
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
{
2+
"type": "File",
3+
"start": 0,
4+
"end": 23,
5+
"loc": {
6+
"start": {
7+
"line": 1,
8+
"column": 0
9+
},
10+
"end": {
11+
"line": 2,
12+
"column": 18
13+
}
14+
},
15+
"program": {
16+
"type": "Program",
17+
"start": 0,
18+
"end": 23,
19+
"loc": {
20+
"start": {
21+
"line": 1,
22+
"column": 0
23+
},
24+
"end": {
25+
"line": 2,
26+
"column": 18
27+
}
28+
},
29+
"sourceType": "module",
30+
"interpreter": null,
31+
"body": [
32+
{
33+
"type": "ExpressionStatement",
34+
"start": 0,
35+
"end": 23,
36+
"loc": {
37+
"start": {
38+
"line": 1,
39+
"column": 0
40+
},
41+
"end": {
42+
"line": 2,
43+
"column": 18
44+
}
45+
},
46+
"expression": {
47+
"type": "ConditionalExpression",
48+
"start": 0,
49+
"end": 23,
50+
"loc": {
51+
"start": {
52+
"line": 1,
53+
"column": 0
54+
},
55+
"end": {
56+
"line": 2,
57+
"column": 18
58+
}
59+
},
60+
"test": {
61+
"type": "Identifier",
62+
"start": 0,
63+
"end": 4,
64+
"loc": {
65+
"start": {
66+
"line": 1,
67+
"column": 0
68+
},
69+
"end": {
70+
"line": 1,
71+
"column": 4
72+
},
73+
"identifierName": "test"
74+
},
75+
"name": "test"
76+
},
77+
"consequent": {
78+
"type": "TypeCastExpression",
79+
"start": 10,
80+
"end": 14,
81+
"loc": {
82+
"start": {
83+
"line": 2,
84+
"column": 5
85+
},
86+
"end": {
87+
"line": 2,
88+
"column": 9
89+
}
90+
},
91+
"expression": {
92+
"type": "Identifier",
93+
"start": 10,
94+
"end": 11,
95+
"loc": {
96+
"start": {
97+
"line": 2,
98+
"column": 5
99+
},
100+
"end": {
101+
"line": 2,
102+
"column": 6
103+
},
104+
"identifierName": "x"
105+
},
106+
"name": "x"
107+
},
108+
"typeAnnotation": {
109+
"type": "TypeAnnotation",
110+
"start": 11,
111+
"end": 14,
112+
"loc": {
113+
"start": {
114+
"line": 2,
115+
"column": 6
116+
},
117+
"end": {
118+
"line": 2,
119+
"column": 9
120+
}
121+
},
122+
"typeAnnotation": {
123+
"type": "GenericTypeAnnotation",
124+
"start": 13,
125+
"end": 14,
126+
"loc": {
127+
"start": {
128+
"line": 2,
129+
"column": 8
130+
},
131+
"end": {
132+
"line": 2,
133+
"column": 9
134+
}
135+
},
136+
"typeParameters": null,
137+
"id": {
138+
"type": "Identifier",
139+
"start": 13,
140+
"end": 14,
141+
"loc": {
142+
"start": {
143+
"line": 2,
144+
"column": 8
145+
},
146+
"end": {
147+
"line": 2,
148+
"column": 9
149+
},
150+
"identifierName": "T"
151+
},
152+
"name": "T"
153+
}
154+
}
155+
},
156+
"extra": {
157+
"parenthesized": true,
158+
"parenStart": 9
159+
}
160+
},
161+
"alternate": {
162+
"type": "ArrowFunctionExpression",
163+
"start": 17,
164+
"end": 23,
165+
"loc": {
166+
"start": {
167+
"line": 2,
168+
"column": 12
169+
},
170+
"end": {
171+
"line": 2,
172+
"column": 18
173+
}
174+
},
175+
"id": null,
176+
"generator": false,
177+
"async": false,
178+
"params": [
179+
{
180+
"type": "Identifier",
181+
"start": 17,
182+
"end": 18,
183+
"loc": {
184+
"start": {
185+
"line": 2,
186+
"column": 12
187+
},
188+
"end": {
189+
"line": 2,
190+
"column": 13
191+
},
192+
"identifierName": "U"
193+
},
194+
"name": "U"
195+
}
196+
],
197+
"body": {
198+
"type": "Identifier",
199+
"start": 22,
200+
"end": 23,
201+
"loc": {
202+
"start": {
203+
"line": 2,
204+
"column": 17
205+
},
206+
"end": {
207+
"line": 2,
208+
"column": 18
209+
},
210+
"identifierName": "y"
211+
},
212+
"name": "y"
213+
}
214+
}
215+
}
216+
}
217+
],
218+
"directives": []
219+
}
220+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test
2+
? (x: T): U => y
3+
: z

0 commit comments

Comments
 (0)