Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/common/reason.ml
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ type reason_desc =
| ROptional of reason_desc
| RMaybe of reason_desc
| RRestArray of reason_desc
| RAbstract of reason_desc
| RTypeApp of reason_desc
| RThisTypeApp of reason_desc
| RExtends of reason_desc
| RStatics of reason_desc
| RSuperOf of reason_desc
| RAbstractsOf of reason_desc
| RFrozen of reason_desc
| RBound of reason_desc
| RVarianceCheck of reason_desc
Expand All @@ -175,6 +175,8 @@ type reason_desc =
| RObjectPatternRestProp
| RArrayPatternRestProp
| RCommonJSExports of string
| RPropertyDef of reason_desc_property
| RMember of string

| RReactProps
| RReactElement of string option
Expand All @@ -195,6 +197,13 @@ and reason_desc_function =
| RAsyncGenerator
| RNormal

and reason_desc_property =
| RFieldDef
| RGetterDef
| RSetterDef
| RMethodDef
| RAbstractMethodDef

type reason = {
test_id: int option;
derivable: bool;
Expand Down Expand Up @@ -505,12 +514,12 @@ let rec string_of_desc = function
in
spf "nullable %s" (string_of_desc (loop d))
| RRestArray d -> spf "rest parameter array of %s" (string_of_desc d)
| RAbstract d -> spf "abstract %s" (string_of_desc d)
| RTypeApp d -> string_of_desc d
| RThisTypeApp d -> spf "this instantiation of %s" (string_of_desc d)
| RExtends d -> spf "extends %s" (string_of_desc d)
| RStatics d -> spf "statics of %s" (string_of_desc d)
| RSuperOf d -> spf "super of %s" (string_of_desc d)
| RAbstractsOf d -> spf "abstracts of %s" (string_of_desc d)
| RFrozen d -> spf "frozen %s" (string_of_desc d)
| RBound d -> spf "bound %s" (string_of_desc d)
| RVarianceCheck d -> spf "variance check: %s" (string_of_desc d)
Expand All @@ -524,6 +533,14 @@ let rec string_of_desc = function
| RObjectPatternRestProp -> "rest of object pattern"
| RArrayPatternRestProp -> "rest of array pattern"
| RCommonJSExports x -> spf "module `%s`" x
| RPropertyDef x ->
(match x with
| RFieldDef -> "field"
| RGetterDef -> "getter"
| RSetterDef -> "setter"
| RMethodDef -> "method"
| RAbstractMethodDef -> "abstract method")
| RMember x -> spf "member `%s`" x

| RReactProps -> "props"
| RReactElement x ->
Expand Down Expand Up @@ -815,12 +832,12 @@ let is_scalar_reason r = match desc_of_reason ~unwrap:true r with
| ROptional _
| RMaybe _
| RRestArray _
| RAbstract _
| RTypeApp _
| RThisTypeApp _
| RExtends _
| RStatics _
| RSuperOf _
| RAbstractsOf _
| RFrozen _
| RBound _
| RVarianceCheck _
Expand All @@ -833,6 +850,8 @@ let is_scalar_reason r = match desc_of_reason ~unwrap:true r with
| RObjectPatternRestProp
| RArrayPatternRestProp
| RCommonJSExports _
| RPropertyDef _
| RMember _
| RReactProps
| RReactElement _
| RReactClass
Expand Down Expand Up @@ -960,12 +979,12 @@ let is_array_reason r = match desc_of_reason ~unwrap:true r with
| RExactType _
| ROptional _
| RMaybe _
| RAbstract _
| RTypeApp _
| RThisTypeApp _
| RExtends _
| RStatics _
| RSuperOf _
| RAbstractsOf _
| RFrozen _
| RBound _
| RVarianceCheck _
Expand All @@ -977,6 +996,8 @@ let is_array_reason r = match desc_of_reason ~unwrap:true r with
| RSpreadOf _
| RObjectPatternRestProp
| RCommonJSExports _
| RPropertyDef _
| RMember _
| RReactProps
| RReactElement _
| RReactClass
Expand Down
11 changes: 10 additions & 1 deletion src/common/reason.mli
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ type reason_desc =
| ROptional of reason_desc
| RMaybe of reason_desc
| RRestArray of reason_desc
| RAbstract of reason_desc
| RTypeApp of reason_desc
| RThisTypeApp of reason_desc
| RExtends of reason_desc
| RStatics of reason_desc
| RSuperOf of reason_desc
| RAbstractsOf of reason_desc
| RFrozen of reason_desc
| RBound of reason_desc
| RVarianceCheck of reason_desc
Expand All @@ -127,6 +127,8 @@ type reason_desc =
| RObjectPatternRestProp
| RArrayPatternRestProp
| RCommonJSExports of string
| RPropertyDef of reason_desc_property
| RMember of string

| RReactProps
| RReactElement of string option
Expand All @@ -147,6 +149,13 @@ and reason_desc_function =
| RAsyncGenerator
| RNormal

and reason_desc_property =
| RFieldDef
| RGetterDef
| RSetterDef
| RMethodDef
| RAbstractMethodDef

type reason
type t = reason (* convenience *)

Expand Down
12 changes: 12 additions & 0 deletions src/parser/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ and Type : sig
end
type 'M t = {
params: 'M Params.t;
async: bool;
generator: bool;
returnType: 'M Type.t;
typeParameters: 'M Type.ParameterDeclaration.t option;
}
Expand Down Expand Up @@ -115,6 +117,7 @@ and Type : sig
key: 'M Expression.Object.Property.key;
value: 'M value;
optional: bool;
abstract: bool;
static: bool;
_method: bool;
variance: 'M Variance.t option;
Expand Down Expand Up @@ -996,6 +999,14 @@ and Comment : sig
end = Comment

and Class : sig
module AbstractMethod : sig
type 'M t = 'M * 'M t'
and 'M t' = {
key: 'M Identifier.t;
value: 'M * 'M Type.Function.t;
static: bool;
}
end
module Method : sig
type 'M t = 'M * 'M t'
and kind =
Expand Down Expand Up @@ -1040,6 +1051,7 @@ and Class : sig
end
module Body : sig
type 'M element =
| AbstractMethod of 'M AbstractMethod.t
| Method of 'M Method.t
| Property of 'M Property.t
| PrivateField of 'M PrivateField.t
Expand Down
14 changes: 13 additions & 1 deletion src/parser/estree_translator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -757,10 +757,19 @@ end with type t = Impl.t) = struct
)

and class_element = Class.Body.(function
| AbstractMethod m -> class_abstract_method m
| Method m -> class_method m
| PrivateField p -> class_private_field p
| Property p -> class_property p)

and class_abstract_method (loc, method_) =
let { Class.AbstractMethod.key; value; static; } = method_ in
node "AbstractMethodDefinition" loc [
"key", identifier key;
"value", function_type value;
"static", bool static;
]

and class_method (loc, method_) =
let { Class.Method.key; value; kind; static; decorators; } = method_ in
let key, computed = Expression.Object.Property.(match key with
Expand Down Expand Up @@ -1071,6 +1080,8 @@ end with type t = Impl.t) = struct
let (_, { Params.params; rest }) = fn.params in
node "FunctionTypeAnnotation" loc [
"params", array_of_list function_type_param params;
"async", bool fn.async;
"generator", bool fn.generator;
"returnType", _type fn.returnType;
"rest", option function_type_rest rest;
"typeParameters", option type_parameter_declaration fn.typeParameters;
Expand Down Expand Up @@ -1119,7 +1130,7 @@ end with type t = Impl.t) = struct
)

and object_type_property (loc, { Type.Object.Property.
key; value; optional; static; variance = variance_; _method;
key; value; optional; abstract; static; variance = variance_; _method;
}) =
let key = match key with
| Expression.Object.Property.Literal lit -> literal lit
Expand All @@ -1139,6 +1150,7 @@ end with type t = Impl.t) = struct
"value", value;
"method", bool _method;
"optional", bool optional;
"abstract", bool abstract;
"static", bool static;
"variance", option variance variance_;
"kind", string kind;
Expand Down
2 changes: 2 additions & 0 deletions src/parser/lexer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ let token (env: Lex_env.t) lexbuf : result =
Token (env, T_NUMBER { kind = NORMAL; raw = lexeme lexbuf })

(* Keywords *)
| "abstract" -> Token (env, T_ABSTRACT)
| "async" -> Token (env, T_ASYNC)
| "await" -> Token (env, T_AWAIT)
| "break" -> Token (env, T_BREAK)
Expand Down Expand Up @@ -1612,6 +1613,7 @@ let type_token env lexbuf =
Token (env, mk_num_singleton NORMAL num)

(* Keywords *)
| "abstract" -> Token (env, T_ABSTRACT)
| "any" -> Token (env, T_ANY_TYPE)
| "bool" -> Token (env, (T_BOOLEAN_TYPE BOOL))
| "boolean" -> Token (env, (T_BOOLEAN_TYPE BOOLEAN))
Expand Down
Loading