Skip to content

Commit 0223ff2

Browse files
samwgoldmanFacebook Github Bot
authored andcommitted
Use a property AST node for mixed types
Reviewed By: avikchaudhuri Differential Revision: D3979312 fbshipit-source-id: 1669566d2fb73c5cfa8f6fe44ade30649be6012e
1 parent 9e0070e commit 0223ff2

File tree

6 files changed

+13
-23
lines changed

6 files changed

+13
-23
lines changed

src/parser/estree_translator.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ end with type t = Impl.t) = struct
918918
and _type (loc, t) = Type.(
919919
match t with
920920
| Any -> any_type loc
921+
| Mixed -> mixed_type loc
921922
| Void -> void_type loc
922923
| Null -> null_type loc
923924
| Number -> number_type loc
@@ -940,6 +941,8 @@ end with type t = Impl.t) = struct
940941

941942
and any_type loc = node "AnyTypeAnnotation" loc [||]
942943

944+
and mixed_type loc = node "MixedTypeAnnotation" loc [||]
945+
943946
and void_type loc = node "VoidTypeAnnotation" loc [||]
944947

945948
and null_type loc = node "NullTypeAnnotation" loc [||]

src/parser/lexer_flow.mll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ module Token = struct
135135
| T_JSX_TEXT of (Loc.t * string * string) (* loc, value, raw *)
136136
(* Type primitives *)
137137
| T_ANY_TYPE
138+
| T_MIXED_TYPE
138139
| T_BOOLEAN_TYPE
139140
| T_NUMBER_TYPE
140141
| T_NUMBER_SINGLETON_TYPE of number_type * float
@@ -275,6 +276,7 @@ module Token = struct
275276
| T_JSX_TEXT _ -> "T_JSX_TEXT"
276277
(* Type primitives *)
277278
| T_ANY_TYPE -> "T_ANY_TYPE"
279+
| T_MIXED_TYPE -> "T_MIXED_TYPE"
278280
| T_BOOLEAN_TYPE -> "T_BOOLEAN_TYPE"
279281
| T_NUMBER_TYPE -> "T_NUMBER_TYPE"
280282
| T_NUMBER_SINGLETON_TYPE _ -> "T_NUMBER_SINGLETON_TYPE"
@@ -725,6 +727,7 @@ end
725727
"static", T_STATIC;
726728
"typeof", T_TYPEOF;
727729
"any", T_ANY_TYPE;
730+
"mixed", T_MIXED_TYPE;
728731
"bool", T_BOOLEAN_TYPE;
729732
"boolean", T_BOOLEAN_TYPE;
730733
"true", T_TRUE;

src/parser/parser_flow.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ end = struct
259259

260260
and primitive = function
261261
| T_ANY_TYPE -> Some Type.Any
262+
| T_MIXED_TYPE -> Some Type.Mixed
262263
| T_BOOLEAN_TYPE -> Some Type.Boolean
263264
| T_NUMBER_TYPE -> Some Type.Number
264265
| T_STRING_TYPE -> Some Type.String

src/parser/spider_monkey_ast.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ and Type : sig
151151
* should never be declared nullable, but that check can happen later *)
152152
and t' =
153153
| Any
154+
| Mixed
154155
| Void
155156
| Null
156157
| Number

src/parser/test/hardcoded_tests.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4234,7 +4234,7 @@ module.exports = {
42344234
'params': [
42354235
{
42364236
'name.name': 'x',
4237-
'typeAnnotation.type': 'GenericTypeAnnotation',
4237+
'typeAnnotation.type': 'MixedTypeAnnotation',
42384238
}
42394239
],
42404240
'returnType.type': 'BooleanTypeAnnotation'
@@ -4276,14 +4276,7 @@ module.exports = {
42764276
'typeAnnotation':{
42774277
'type':'TypeAnnotation',
42784278
'typeAnnotation':{
4279-
'type':'GenericTypeAnnotation',
4280-
'id':{
4281-
'type':'Identifier',
4282-
'name':'mixed',
4283-
'typeAnnotation':null,
4284-
'optional':false
4285-
},
4286-
'typeParameters':null
4279+
'type':'MixedTypeAnnotation',
42874280
}
42884281
},
42894282
'optional':false
@@ -4342,14 +4335,7 @@ module.exports = {
43424335
'typeAnnotation':{
43434336
'type':'TypeAnnotation',
43444337
'typeAnnotation':{
4345-
'type':'GenericTypeAnnotation',
4346-
'id':{
4347-
'type':'Identifier',
4348-
'name':'mixed',
4349-
'typeAnnotation':null,
4350-
'optional':false
4351-
},
4352-
'typeParameters':null
4338+
'type':'MixedTypeAnnotation',
43534339
}
43544340
},
43554341
'optional':false

src/typing/type_annotation.ml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ let rec convert cx tparams_map = Ast.Type.(function
5353

5454
| loc, Any -> AnyT.at loc
5555

56+
| loc, Mixed -> MixedT.at loc
57+
5658
| loc, Void -> VoidT.at loc
5759

5860
| loc, Null -> NullT.at loc
@@ -165,12 +167,6 @@ let rec convert cx tparams_map = Ast.Type.(function
165167

166168
begin match name with
167169

168-
(* TODO Type.Mixed *)
169-
| "mixed" ->
170-
check_type_param_arity cx loc typeParameters 0 (fun () ->
171-
MixedT.at loc
172-
)
173-
174170
(* Array<T> *)
175171
| "Array" ->
176172
check_type_param_arity cx loc typeParameters 1 (fun () ->

0 commit comments

Comments
 (0)