Skip to content

Commit

Permalink
Use a property AST node for mixed types
Browse files Browse the repository at this point in the history
Reviewed By: avikchaudhuri

Differential Revision: D3979312

fbshipit-source-id: 1669566d2fb73c5cfa8f6fe44ade30649be6012e
  • Loading branch information
samwgoldman authored and Facebook Github Bot committed Oct 6, 2016
1 parent 9e0070e commit 0223ff2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 23 deletions.
3 changes: 3 additions & 0 deletions src/parser/estree_translator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ end with type t = Impl.t) = struct
and _type (loc, t) = Type.(
match t with
| Any -> any_type loc
| Mixed -> mixed_type loc
| Void -> void_type loc
| Null -> null_type loc
| Number -> number_type loc
Expand All @@ -940,6 +941,8 @@ end with type t = Impl.t) = struct

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

and mixed_type loc = node "MixedTypeAnnotation" loc [||]

and void_type loc = node "VoidTypeAnnotation" loc [||]

and null_type loc = node "NullTypeAnnotation" loc [||]
Expand Down
3 changes: 3 additions & 0 deletions src/parser/lexer_flow.mll
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ module Token = struct
| T_JSX_TEXT of (Loc.t * string * string) (* loc, value, raw *)
(* Type primitives *)
| T_ANY_TYPE
| T_MIXED_TYPE
| T_BOOLEAN_TYPE
| T_NUMBER_TYPE
| T_NUMBER_SINGLETON_TYPE of number_type * float
Expand Down Expand Up @@ -275,6 +276,7 @@ module Token = struct
| T_JSX_TEXT _ -> "T_JSX_TEXT"
(* Type primitives *)
| T_ANY_TYPE -> "T_ANY_TYPE"
| T_MIXED_TYPE -> "T_MIXED_TYPE"
| T_BOOLEAN_TYPE -> "T_BOOLEAN_TYPE"
| T_NUMBER_TYPE -> "T_NUMBER_TYPE"
| T_NUMBER_SINGLETON_TYPE _ -> "T_NUMBER_SINGLETON_TYPE"
Expand Down Expand Up @@ -725,6 +727,7 @@ end
"static", T_STATIC;
"typeof", T_TYPEOF;
"any", T_ANY_TYPE;
"mixed", T_MIXED_TYPE;
"bool", T_BOOLEAN_TYPE;
"boolean", T_BOOLEAN_TYPE;
"true", T_TRUE;
Expand Down
1 change: 1 addition & 0 deletions src/parser/parser_flow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ end = struct

and primitive = function
| T_ANY_TYPE -> Some Type.Any
| T_MIXED_TYPE -> Some Type.Mixed
| T_BOOLEAN_TYPE -> Some Type.Boolean
| T_NUMBER_TYPE -> Some Type.Number
| T_STRING_TYPE -> Some Type.String
Expand Down
1 change: 1 addition & 0 deletions src/parser/spider_monkey_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ and Type : sig
* should never be declared nullable, but that check can happen later *)
and t' =
| Any
| Mixed
| Void
| Null
| Number
Expand Down
20 changes: 3 additions & 17 deletions src/parser/test/hardcoded_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4234,7 +4234,7 @@ module.exports = {
'params': [
{
'name.name': 'x',
'typeAnnotation.type': 'GenericTypeAnnotation',
'typeAnnotation.type': 'MixedTypeAnnotation',
}
],
'returnType.type': 'BooleanTypeAnnotation'
Expand Down Expand Up @@ -4276,14 +4276,7 @@ module.exports = {
'typeAnnotation':{
'type':'TypeAnnotation',
'typeAnnotation':{
'type':'GenericTypeAnnotation',
'id':{
'type':'Identifier',
'name':'mixed',
'typeAnnotation':null,
'optional':false
},
'typeParameters':null
'type':'MixedTypeAnnotation',
}
},
'optional':false
Expand Down Expand Up @@ -4342,14 +4335,7 @@ module.exports = {
'typeAnnotation':{
'type':'TypeAnnotation',
'typeAnnotation':{
'type':'GenericTypeAnnotation',
'id':{
'type':'Identifier',
'name':'mixed',
'typeAnnotation':null,
'optional':false
},
'typeParameters':null
'type':'MixedTypeAnnotation',
}
},
'optional':false
Expand Down
8 changes: 2 additions & 6 deletions src/typing/type_annotation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ let rec convert cx tparams_map = Ast.Type.(function

| loc, Any -> AnyT.at loc

| loc, Mixed -> MixedT.at loc

| loc, Void -> VoidT.at loc

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

begin match name with

(* TODO Type.Mixed *)
| "mixed" ->
check_type_param_arity cx loc typeParameters 0 (fun () ->
MixedT.at loc
)

(* Array<T> *)
| "Array" ->
check_type_param_arity cx loc typeParameters 1 (fun () ->
Expand Down

0 comments on commit 0223ff2

Please sign in to comment.