This repository was archived by the owner on May 19, 2018. It is now read-only.
Commit 874ff76 1 parent 2ef4366 commit 874ff76 Copy full SHA for 874ff76
File tree 5 files changed +695
-8
lines changed
test/fixtures/flow/type-generics
5 files changed +695
-8
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint max-len: 0 */
2
2
3
3
import { types as tt } from "../tokenizer/types" ;
4
- import { types as ct } from "../tokenizer/context" ;
5
4
import Parser from "../parser" ;
6
5
7
6
const primitiveTypes = [
@@ -1378,6 +1377,12 @@ export default function (instance) {
1378
1377
} catch ( err ) {
1379
1378
if ( err instanceof SyntaxError ) {
1380
1379
this . state = state ;
1380
+
1381
+ // Remove `tc.j_expr` and `tc.j_oTag` from context added by
1382
+ // by parsing `jsxTagStart` to stop the JSX plugin from
1383
+ // messing with the tokens
1384
+ this . state . context . length -= 2 ;
1385
+
1381
1386
jsxError = err ;
1382
1387
} else {
1383
1388
// istanbul ignore next: no such error is expected
@@ -1387,9 +1392,6 @@ export default function (instance) {
1387
1392
}
1388
1393
1389
1394
if ( jsxError != null || this . isRelational ( "<" ) ) {
1390
- // Need to push something onto the context to stop
1391
- // the JSX plugin from messing with the tokens
1392
- this . state . context . push ( ct . parenExpression ) ;
1393
1395
let arrowExpression ;
1394
1396
let typeParameters ;
1395
1397
try {
@@ -1399,13 +1401,9 @@ export default function (instance) {
1399
1401
arrowExpression . typeParameters = typeParameters ;
1400
1402
this . resetStartLocationFromNode ( arrowExpression , typeParameters ) ;
1401
1403
} catch ( err ) {
1402
- this . state . context . pop ( ) ;
1403
-
1404
1404
throw jsxError || err ;
1405
1405
}
1406
1406
1407
- this . state . context . pop ( ) ;
1408
-
1409
1407
if ( arrowExpression . type === "ArrowFunctionExpression" ) {
1410
1408
return arrowExpression ;
1411
1409
} else if ( jsxError != null ) {
Original file line number Diff line number Diff line change
1
+ const functionReturningIdentityAsAField = ( ) => ( { id : < T > (value: T): T => value } ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "type" : " File" ,
3
+ "start" : 0 ,
4
+ "end" : 84 ,
5
+ "loc" : {
6
+ "start" : {
7
+ "line" : 1 ,
8
+ "column" : 0
9
+ },
10
+ "end" : {
11
+ "line" : 1 ,
12
+ "column" : 84
13
+ }
14
+ },
15
+ "program" : {
16
+ "type" : " Program" ,
17
+ "start" : 0 ,
18
+ "end" : 84 ,
19
+ "loc" : {
20
+ "start" : {
21
+ "line" : 1 ,
22
+ "column" : 0
23
+ },
24
+ "end" : {
25
+ "line" : 1 ,
26
+ "column" : 84
27
+ }
28
+ },
29
+ "sourceType" : " module" ,
30
+ "body" : [
31
+ {
32
+ "type" : " VariableDeclaration" ,
33
+ "start" : 0 ,
34
+ "end" : 84 ,
35
+ "loc" : {
36
+ "start" : {
37
+ "line" : 1 ,
38
+ "column" : 0
39
+ },
40
+ "end" : {
41
+ "line" : 1 ,
42
+ "column" : 84
43
+ }
44
+ },
45
+ "declarations" : [
46
+ {
47
+ "type" : " VariableDeclarator" ,
48
+ "start" : 6 ,
49
+ "end" : 83 ,
50
+ "loc" : {
51
+ "start" : {
52
+ "line" : 1 ,
53
+ "column" : 6
54
+ },
55
+ "end" : {
56
+ "line" : 1 ,
57
+ "column" : 83
58
+ }
59
+ },
60
+ "id" : {
61
+ "type" : " Identifier" ,
62
+ "start" : 6 ,
63
+ "end" : 39 ,
64
+ "loc" : {
65
+ "start" : {
66
+ "line" : 1 ,
67
+ "column" : 6
68
+ },
69
+ "end" : {
70
+ "line" : 1 ,
71
+ "column" : 39
72
+ },
73
+ "identifierName" : " functionReturningIdentityAsAField"
74
+ },
75
+ "name" : " functionReturningIdentityAsAField"
76
+ },
77
+ "init" : {
78
+ "type" : " ArrowFunctionExpression" ,
79
+ "start" : 42 ,
80
+ "end" : 83 ,
81
+ "loc" : {
82
+ "start" : {
83
+ "line" : 1 ,
84
+ "column" : 42
85
+ },
86
+ "end" : {
87
+ "line" : 1 ,
88
+ "column" : 83
89
+ }
90
+ },
91
+ "id" : null ,
92
+ "generator" : false ,
93
+ "expression" : true ,
94
+ "async" : false ,
95
+ "params" : [],
96
+ "body" : {
97
+ "type" : " ObjectExpression" ,
98
+ "start" : 49 ,
99
+ "end" : 82 ,
100
+ "loc" : {
101
+ "start" : {
102
+ "line" : 1 ,
103
+ "column" : 49
104
+ },
105
+ "end" : {
106
+ "line" : 1 ,
107
+ "column" : 82
108
+ }
109
+ },
110
+ "properties" : [
111
+ {
112
+ "type" : " ObjectProperty" ,
113
+ "start" : 51 ,
114
+ "end" : 80 ,
115
+ "loc" : {
116
+ "start" : {
117
+ "line" : 1 ,
118
+ "column" : 51
119
+ },
120
+ "end" : {
121
+ "line" : 1 ,
122
+ "column" : 80
123
+ }
124
+ },
125
+ "method" : false ,
126
+ "shorthand" : false ,
127
+ "computed" : false ,
128
+ "key" : {
129
+ "type" : " Identifier" ,
130
+ "start" : 51 ,
131
+ "end" : 53 ,
132
+ "loc" : {
133
+ "start" : {
134
+ "line" : 1 ,
135
+ "column" : 51
136
+ },
137
+ "end" : {
138
+ "line" : 1 ,
139
+ "column" : 53
140
+ },
141
+ "identifierName" : " id"
142
+ },
143
+ "name" : " id"
144
+ },
145
+ "value" : {
146
+ "type" : " ArrowFunctionExpression" ,
147
+ "start" : 55 ,
148
+ "end" : 80 ,
149
+ "loc" : {
150
+ "start" : {
151
+ "line" : 1 ,
152
+ "column" : 55
153
+ },
154
+ "end" : {
155
+ "line" : 1 ,
156
+ "column" : 80
157
+ }
158
+ },
159
+ "predicate" : null ,
160
+ "returnType" : {
161
+ "type" : " TypeAnnotation" ,
162
+ "start" : 68 ,
163
+ "end" : 71 ,
164
+ "loc" : {
165
+ "start" : {
166
+ "line" : 1 ,
167
+ "column" : 68
168
+ },
169
+ "end" : {
170
+ "line" : 1 ,
171
+ "column" : 71
172
+ }
173
+ },
174
+ "typeAnnotation" : {
175
+ "type" : " GenericTypeAnnotation" ,
176
+ "start" : 70 ,
177
+ "end" : 71 ,
178
+ "loc" : {
179
+ "start" : {
180
+ "line" : 1 ,
181
+ "column" : 70
182
+ },
183
+ "end" : {
184
+ "line" : 1 ,
185
+ "column" : 71
186
+ }
187
+ },
188
+ "typeParameters" : null ,
189
+ "id" : {
190
+ "type" : " Identifier" ,
191
+ "start" : 70 ,
192
+ "end" : 71 ,
193
+ "loc" : {
194
+ "start" : {
195
+ "line" : 1 ,
196
+ "column" : 70
197
+ },
198
+ "end" : {
199
+ "line" : 1 ,
200
+ "column" : 71
201
+ },
202
+ "identifierName" : " T"
203
+ },
204
+ "name" : " T"
205
+ }
206
+ }
207
+ },
208
+ "id" : null ,
209
+ "generator" : false ,
210
+ "expression" : true ,
211
+ "async" : false ,
212
+ "params" : [
213
+ {
214
+ "type" : " Identifier" ,
215
+ "start" : 59 ,
216
+ "end" : 67 ,
217
+ "loc" : {
218
+ "start" : {
219
+ "line" : 1 ,
220
+ "column" : 59
221
+ },
222
+ "end" : {
223
+ "line" : 1 ,
224
+ "column" : 67
225
+ },
226
+ "identifierName" : " value"
227
+ },
228
+ "name" : " value" ,
229
+ "typeAnnotation" : {
230
+ "type" : " TypeAnnotation" ,
231
+ "start" : 64 ,
232
+ "end" : 67 ,
233
+ "loc" : {
234
+ "start" : {
235
+ "line" : 1 ,
236
+ "column" : 64
237
+ },
238
+ "end" : {
239
+ "line" : 1 ,
240
+ "column" : 67
241
+ }
242
+ },
243
+ "typeAnnotation" : {
244
+ "type" : " GenericTypeAnnotation" ,
245
+ "start" : 66 ,
246
+ "end" : 67 ,
247
+ "loc" : {
248
+ "start" : {
249
+ "line" : 1 ,
250
+ "column" : 66
251
+ },
252
+ "end" : {
253
+ "line" : 1 ,
254
+ "column" : 67
255
+ }
256
+ },
257
+ "typeParameters" : null ,
258
+ "id" : {
259
+ "type" : " Identifier" ,
260
+ "start" : 66 ,
261
+ "end" : 67 ,
262
+ "loc" : {
263
+ "start" : {
264
+ "line" : 1 ,
265
+ "column" : 66
266
+ },
267
+ "end" : {
268
+ "line" : 1 ,
269
+ "column" : 67
270
+ },
271
+ "identifierName" : " T"
272
+ },
273
+ "name" : " T"
274
+ }
275
+ }
276
+ }
277
+ }
278
+ ],
279
+ "body" : {
280
+ "type" : " Identifier" ,
281
+ "start" : 75 ,
282
+ "end" : 80 ,
283
+ "loc" : {
284
+ "start" : {
285
+ "line" : 1 ,
286
+ "column" : 75
287
+ },
288
+ "end" : {
289
+ "line" : 1 ,
290
+ "column" : 80
291
+ },
292
+ "identifierName" : " value"
293
+ },
294
+ "name" : " value"
295
+ },
296
+ "typeParameters" : {
297
+ "type" : " TypeParameterDeclaration" ,
298
+ "start" : 55 ,
299
+ "end" : 58 ,
300
+ "loc" : {
301
+ "start" : {
302
+ "line" : 1 ,
303
+ "column" : 55
304
+ },
305
+ "end" : {
306
+ "line" : 1 ,
307
+ "column" : 58
308
+ }
309
+ },
310
+ "params" : [
311
+ {
312
+ "type" : " TypeParameter" ,
313
+ "start" : 56 ,
314
+ "end" : 57 ,
315
+ "loc" : {
316
+ "start" : {
317
+ "line" : 1 ,
318
+ "column" : 56
319
+ },
320
+ "end" : {
321
+ "line" : 1 ,
322
+ "column" : 57
323
+ }
324
+ },
325
+ "name" : " T" ,
326
+ "variance" : null
327
+ }
328
+ ]
329
+ }
330
+ }
331
+ }
332
+ ],
333
+ "extra" : {
334
+ "parenthesized" : true ,
335
+ "parenStart" : 48
336
+ }
337
+ }
338
+ }
339
+ }
340
+ ],
341
+ "kind" : " const"
342
+ }
343
+ ],
344
+ "directives" : []
345
+ }
346
+ }
Original file line number Diff line number Diff line change
1
+ const identity = < T > (t: T): T => t ;
2
+ const a = 1 ;
You can’t perform that action at this time.
0 commit comments