diff --git a/src/common/reason.ml b/src/common/reason.ml index 651931d7ec8..97ebd1db52d 100644 --- a/src/common/reason.ml +++ b/src/common/reason.ml @@ -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 @@ -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 @@ -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; @@ -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) @@ -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 -> @@ -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 _ @@ -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 @@ -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 _ @@ -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 diff --git a/src/common/reason.mli b/src/common/reason.mli index 20517659d71..68dd616e182 100644 --- a/src/common/reason.mli +++ b/src/common/reason.mli @@ -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 @@ -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 @@ -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 *) diff --git a/src/parser/ast.ml b/src/parser/ast.ml index 1ec9e4bc42a..ad342d3207c 100644 --- a/src/parser/ast.ml +++ b/src/parser/ast.ml @@ -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; } @@ -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; @@ -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 = @@ -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 diff --git a/src/parser/estree_translator.ml b/src/parser/estree_translator.ml index 19c66ad7689..dbf39c23b4b 100644 --- a/src/parser/estree_translator.ml +++ b/src/parser/estree_translator.ml @@ -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 @@ -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; @@ -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 @@ -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; diff --git a/src/parser/lexer.ml b/src/parser/lexer.ml index d9f6dfffcab..aaddcc75b28 100644 --- a/src/parser/lexer.ml +++ b/src/parser/lexer.ml @@ -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) @@ -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)) diff --git a/src/parser/object_members.ml b/src/parser/object_members.ml new file mode 100644 index 00000000000..5933cb39951 --- /dev/null +++ b/src/parser/object_members.ml @@ -0,0 +1,252 @@ +(** + * Copyright (c) 2013-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + *) + +open Ast +open Parser_env +module Error = Parse_error +module SSet = Set.Make(String) + +module SMap = struct + include Map.Make(String) + let get x t = try Some (find x t) with Not_found -> None +end + +type mark = + | Abstract of Loc.t + | Native + +let empty = (SSet.empty, SMap.empty, SMap.empty, []) + +let members (_, _, _, members) = List.rev members + +let property_name = Expression.Object.Property.(function + | Literal (_, { Literal.value = Literal.String n; _; }) + | Identifier (_, n) -> + Some n + | PrivateName (_, (_, n)) -> Some ("#" ^ n) + | _ -> None) + +module type S = sig + type internal_t + + module AbstractMethod : sig + type t + val is_static: t -> bool + val intern: t -> internal_t + val add: env -> Loc.t Variance.t option -> t -> mark SMap.t -> mark SMap.t + end + module Method : sig + type t + val is_static: t -> bool + val intern: t -> internal_t + val add: env -> Loc.t Variance.t option -> t -> mark SMap.t -> mark SMap.t + end + module Property : sig + type t + val is_static: t -> bool + val intern: t -> internal_t + val add: env -> Loc.t option -> t -> mark SMap.t -> mark SMap.t + end + module Getter : sig + type t + val is_static: t -> bool + val intern: t -> internal_t + val add: env -> Loc.t option -> Loc.t Variance.t option -> t -> mark SMap.t -> mark SMap.t + end + module Setter : sig + type t + val is_static: t -> bool + val intern: t -> internal_t + val add: env -> Loc.t option -> Loc.t Variance.t option -> t -> mark SMap.t -> mark SMap.t + end +end + +module Make(X : S) = struct + type abstract_method_t = X.AbstractMethod.t + type method_t = X.Method.t + type property_t = X.Property.t + + let add_member m (privates, static_marks, marks, members) = + (privates, static_marks, marks, m::members) + + let update_privates f (privates, static_marks, marks, methods) = + (f privates, static_marks, marks, methods) + + let update_marks ~static f (privates, static_marks, marks, methods) = + if static + then (privates, f static_marks, marks, methods) + else (privates, static_marks, f marks, methods) + + let add_abstract_method env variance (m: X.AbstractMethod.t) t = + let static = X.AbstractMethod.is_static m in + let f = X.AbstractMethod.add env variance m in + t |> update_marks ~static f |> add_member (X.AbstractMethod.intern m) + + let add_method env variance (m: X.Method.t) t = + let static = X.Method.is_static m in + let f = X.Method.add env variance m in + t |> update_marks ~static f |> add_member (X.Method.intern m) + + let add_property env abstract (p: X.Property.t) t = + let static = X.Property.is_static p in + let f = X.Property.add env abstract p in + t |> update_marks ~static f |> add_member (X.Property.intern p) + + let add_getter env abstract variance (g: X.Getter.t) t = + let static = X.Getter.is_static g in + let f = X.Getter.add env abstract variance g in + t |> update_marks ~static f |> add_member (X.Getter.intern g) + + let add_setter env abstract variance (s: X.Setter.t) t = + let static = X.Setter.is_static s in + let f = X.Setter.add env abstract variance s in + t |> update_marks ~static f |> add_member (X.Setter.intern s) +end + +module type MemberS = sig + type t + type internal_t + val loc: t -> Loc.t + val name: t -> string option + val is_static: t -> bool + val intern: t -> internal_t +end + +module AbstractMethod(X : MemberS) = struct + type t = X.t + + let is_static = X.is_static + let intern = X.intern + + let add env variance t marks = + match X.is_static t, variance, X.name t with + | _, Some (loc, _), _ -> + error_at env (loc, Error.UnexpectedVariance); + marks + | _, None, Some "constructor" -> + error_at env (X.loc t, Error.AbstractConstructor); + marks + | true, None, Some "name" -> + error_at env (X.loc t, Error.AbstractStaticName); + marks + | _, None, None -> marks + | _, None, Some name -> + match SMap.get name marks with + | Some (Abstract _) -> + error_at env (X.loc t, Error.DuplicateAbstractMethods name); + marks + | Some Native -> + error_at env (X.loc t, Error.ImmediateAbstract name); + marks + | None -> + SMap.add name (Abstract (X.loc t)) marks +end + +module Method(X : MemberS) = struct + type t = X.t + + let is_static = X.is_static + let intern = X.intern + + let add env variance t marks = + match variance with + | Some (loc, _) -> + error_at env (loc, Error.UnexpectedVariance); + marks + | None -> + match X.name t with + | None -> marks + | Some name -> + match SMap.get name marks with + | Some (Abstract loc) -> + error_at env (loc, Error.ImmediateAbstract name); + marks + | Some Native -> marks + | None -> SMap.add name Native marks +end + +module Property(X : MemberS) = struct + type t = X.t + + let is_static = X.is_static + let intern = X.intern + + let add env abstract t marks = + match abstract with + | Some _ -> + error_at env (X.loc t, Error.AbstractProperty); + marks + | None -> + match X.name t with + | None -> marks + | Some name -> + match SMap.get name marks with + | Some (Abstract loc) -> + error_at env (loc, Error.ImmediateAbstract name); + marks + | Some Native -> marks + | None -> SMap.add name Native marks +end + +module Etter (X : MemberS) (Y : sig + val error: Error.t +end) = struct + type t = X.t + + let is_static = X.is_static + let intern = X.intern + + let add env abstract variance t marks = + match abstract, variance with + | Some _, _ -> + error_at env (X.loc t, Y.error); + marks + | None, Some (loc, _) -> + error_at env (loc, Error.UnexpectedVariance); + marks + | None, None -> + match X.name t with + | None -> marks + | Some name -> + match SMap.get name marks with + | Some (Abstract loc) -> + error_at env (loc, Error.ImmediateAbstract name); + marks + | Some Native -> marks + | None -> SMap.add name Native marks +end + +module Getter(X : MemberS) = Etter (X) (struct + let error = Error.AbstractGetter +end) + +module Setter(X : MemberS) = Etter (X) (struct + let error = Error.AbstractSetter +end) + +module PrivateField = struct + type t = Loc.t Class.PrivateField.t + + let intern t = Class.Body.PrivateField t + + let add env abstract t privates = + match abstract with + | Some _ -> + let loc, _ = t in + error_at env (loc, Error.AbstractProperty); + privates + | None -> + Class.PrivateField.(match t with + | _, {key = (loc, (_, "constructor")); static; _} -> + let error = Error.InvalidFieldName ("constructor", static, true) in + error_at env (loc, error); + privates + | _, {key = (loc, (_, name)); _} -> + if SSet.mem name privates + then (error_at env (loc, Error.DuplicatePrivateFields name); privates) + else SSet.add name privates) +end diff --git a/src/parser/object_parser.ml b/src/parser/object_parser.ml index 9be962579b8..e3d5fedc2eb 100644 --- a/src/parser/object_parser.ml +++ b/src/parser/object_parser.ml @@ -382,58 +382,22 @@ module Object | _ -> List.rev acc and class_body = - let rec elements env seen_constructor private_names acc = + let rec elements env acc = match Peek.token env with | T_EOF - | T_RCURLY -> List.rev acc + | T_RCURLY -> acc | T_SEMICOLON -> (* Skip empty elements *) Expect.token env T_SEMICOLON; - elements env seen_constructor private_names acc + elements env acc | _ -> - let element = class_element env in - let seen_constructor', private_names' = begin match element with - | Ast.Class.Body.Method (loc, m) -> - let open Ast.Class.Method in - begin match m.kind with - | Constructor when not m.static -> - if seen_constructor then - error_at env (loc, Error.DuplicateConstructor); - (true, private_names) - | Method -> - (seen_constructor, begin match m.key with - | Ast.Expression.Object.Property.PrivateName _ -> - error_at env (loc, Error.PrivateMethod); - private_names - | _ -> private_names - end) - | _ -> (seen_constructor, private_names) - end - | Ast.Class.Body.Property (loc, p) -> - let open Ast.Expression.Object.Property in - (seen_constructor, begin match p.Ast.Class.Property.key with - | Identifier (_, x) when String.equal x "constructor" || - (String.equal x "prototype" && p.Ast.Class.Property.static) -> - error_at env (loc, Error.InvalidFieldName (x, String.equal x "prototype", false)); - private_names - | _ -> private_names - end) - | Ast.Class.Body.PrivateField (_, {Ast.Class.PrivateField.key = (loc, (_, name)); _}) - when String.equal name "#constructor" -> - error_at env (loc, Error.InvalidFieldName (name, false, true)); - (seen_constructor, private_names) - | Ast.Class.Body.PrivateField (_, {Ast.Class.PrivateField.key = (loc, (_, name)); _}) -> - if SSet.mem name private_names then - error_at env (loc, Error.DuplicatePrivateFields name); - (seen_constructor, SSet.add name private_names) - end in - elements env seen_constructor' private_names' (element::acc) + elements env (class_element env acc) in fun env -> let start_loc = Peek.loc env in Expect.token env T_LCURLY; enter_class env; - let body = elements env false SSet.empty [] in + let body = Object_members.members (elements env Object_members.empty) in exit_class env; let end_loc = Peek.loc env in Expect.token env T_RCURLY; @@ -444,186 +408,383 @@ module Object (* In the ES6 draft, all elements are methods. No properties (though there * are getter and setters allowed *) and class_element = - let get env start_loc decorators static = - let key, (end_loc, _ as value) = - getter_or_setter env true in - Ast.Class.(Body.Method (Loc.btwn start_loc end_loc, Method.({ + let module Members = struct + include Object_members.Make(struct + type internal_t = Loc.t Class.Body.element + + module AbstractMethod = Object_members.AbstractMethod(struct + type t = Loc.t Ast.Class.AbstractMethod.t + type internal_t = Loc.t Ast.Class.Body.element + let loc (loc, _) = loc + let name (_, m) = Some (snd m.Ast.Class.AbstractMethod.key) + let is_static (_, m) = m.Ast.Class.AbstractMethod.static + let intern t = Ast.Class.Body.AbstractMethod t + end) + module Method = struct + include Object_members.Method(struct + type t = Loc.t Ast.Class.Method.t + type internal_t = Loc.t Ast.Class.Body.element + let loc (loc, _) = loc + let name (_, m) = Object_members.property_name m.Ast.Class.Method.key + let is_static (_, m) = m.Ast.Class.Method.static + let intern t = Ast.Class.Body.Method t + end) + let add env variance t marks = + let open Ast.Expression.Object.Property in + match t with + | loc, {Class.Method.key = PrivateName _; _} -> + error_at env (loc, Error.PrivateMethod); + marks + | loc, {Class.Method.kind = Class.Method.Constructor; _} -> + let open Object_members in + let name = "constructor" in + begin match SMap.get name marks with + | Some Native -> + error_at env (loc, Error.DuplicateConstructor); + marks + | _ -> + SMap.add name Native marks + end + | _ -> add env variance t marks + end + module Property = struct + include Object_members.Property(struct + type t = Loc.t Class.Property.t + type internal_t = Loc.t Ast.Class.Body.element + let loc (loc, _) = loc + let name (_, p) = Object_members.property_name p.Class.Property.key + let is_static (_, p) = p.Class.Property.static + let intern t = Ast.Class.Body.Property t + end) + let add env abstract t marks = + let open Ast.Expression.Object.Property in + let (loc, p) = t in + Class.(match p with + | {Property.key = Identifier (_, "constructor"); static; _} -> + let e = Error.InvalidFieldName ("constructor", static, false) in + error_at env (loc, e); + marks + | {Property.key = Identifier (_, "prototype"); static = true; _} -> + let e = Error.InvalidFieldName ("prototype", true, false) in + error_at env (loc, e); + marks + | _ -> add env abstract t marks) + end + module Getter = struct + include Object_members.Getter(struct + type t = Loc.t Ast.Class.Method.t + type internal_t = Loc.t Ast.Class.Body.element + let loc (loc, _) = loc + let name (_, m) = Object_members.property_name m.Ast.Class.Method.key + let is_static (_, m) = m.Ast.Class.Method.static + let intern t = Ast.Class.Body.Method t + end) + let add env abstract variance t marks = + let open Ast.Expression.Object.Property in + match t with + | loc, {Class.Method.key = PrivateName _; _} -> + error_at env (loc, Error.PrivateGetter); + marks + | _ -> add env abstract variance t marks + end + module Setter = struct + include Object_members.Setter(struct + type t = Loc.t Ast.Class.Method.t + type internal_t = Loc.t Ast.Class.Body.element + let loc (loc, _) = loc + let name (_, m) = Object_members.property_name m.Ast.Class.Method.key + let is_static (_, m) = m.Ast.Class.Method.static + let intern t = Ast.Class.Body.Method t + end) + let add env abstract variance t marks = + let open Ast.Expression.Object.Property in + match t with + | loc, {Class.Method.key = PrivateName _; _} -> + error_at env (loc, Error.PrivateSetter); + marks + | _ -> add env abstract variance t marks + end + end) + + let add_private_property env abstract (p: Object_members.PrivateField.t) t = + if abstract <> None then error_at env (fst p, Error.AbstractPrivate); + let open Object_members.PrivateField in + let f = add env abstract p in + t |> update_privates f |> add_member (intern p) + end + + in let class_get env start decorators static = + let key, (end_loc, _ as value) = getter_or_setter env true in + Loc.btwn start end_loc, Ast.Class.Method.({ key; value; kind = Get; - static; + static = static <> None; decorators; - }))) + }) - in let set env start_loc decorators static = - let key, (end_loc, _ as value) = - getter_or_setter env false in - Ast.Class.(Body.Method (Loc.btwn start_loc end_loc, Method.({ + in let class_set env start decorators static = + let key, (end_loc, _ as value) = getter_or_setter env false in + Loc.btwn start end_loc, Ast.Class.Method.({ key; value; kind = Set; - static; + static = static <> None; decorators; - }))) - - in let error_unsupported_variance env = function - | Some (loc, _) -> error_at env (loc, Error.UnexpectedVariance) - | None -> () + }) - in let rec init env start_loc decorators key async generator static variance = - match Peek.token env with - | T_COLON - | T_ASSIGN - | T_SEMICOLON when not async && not generator -> - (* Class property with annotation *) - let end_loc, (typeAnnotation, value) = with_loc (fun env -> - let typeAnnotation = Type.annotation_opt env in - let options = parse_options env in - let value = - if Peek.token env = T_ASSIGN then ( - if static && options.esproposal_class_static_fields - || (not static) && options.esproposal_class_instance_fields - then begin - Expect.token env T_ASSIGN; - Some (Parse.expression (env |> with_allow_super Super_prop)) - end else None - ) else None - in - begin if Expect.maybe env T_SEMICOLON then - () - else if Peek.token env == T_LBRACKET || Peek.token env == T_LPAREN then - error_unexpected env - end; - typeAnnotation, value - ) env in - let loc = Loc.btwn start_loc end_loc in - begin match key with - | Ast.Expression.Object.Property.PrivateName private_name -> - Ast.Class.(Body.PrivateField (loc, PrivateField.({ - key = private_name; - value; - typeAnnotation; - static; - variance; - }))) - | _ -> Ast.Class.(Body.Property (loc, Property.({ - key; - value; - typeAnnotation; - static; - variance; - }))) end - | T_PLING -> - (* TODO: add support for optional class properties *) - error_unexpected env; - Eat.token env; - init env start_loc decorators key async generator static variance - | _ -> - error_unsupported_variance env variance; - let kind, env = match static, key with - | false, Ast.Expression.Object.Property.Identifier (_, "constructor") - | false, Ast.Expression.Object.Property.Literal (_, { - Literal.value = Literal.String "constructor"; - _; - }) -> - Ast.Class.Method.Constructor, - env |> with_allow_super Super_prop_or_call - | _ -> - Ast.Class.Method.Method, - env |> with_allow_super Super_prop - in - let func_loc = Peek.loc env in + in let class_abstract_method env start keywords generator key = + let (abstract, static, async) = keywords in + assert(abstract <> None); + let value = with_loc (fun env -> let typeParameters = Type.type_parameter_declaration env in - let params = - let yield, await = match async, generator with - | true, true -> true, true (* proposal-async-iteration/#prod-AsyncGeneratorMethod *) - | true, false -> false, allow_await env (* #prod-AsyncMethod *) - | false, true -> true, false (* #prod-GeneratorMethod *) - | false, false -> false, false (* #prod-MethodDefinition *) - in - Declaration.function_params ~await ~yield env - in - let returnType = Type.annotation_opt env in - let _, body, strict = - Declaration.function_body env ~async ~generator in - let simple = Declaration.is_simple_function_params params in - Declaration.strict_post_check env ~strict ~simple None params; - let end_loc, expression = Function.( - match body with - | BodyBlock (loc, _) -> loc, false - | BodyExpression (loc, _) -> loc, true) in - let loc = Loc.btwn func_loc end_loc in - let value = loc, Function.({ - id = None; + let params = Type.function_param_list env in + Expect.token env T_COLON; + let returnType = Type._type env in + ignore (Expect.maybe env T_SEMICOLON); + Ast.Type.Function.({ params; - body; + async = async <> None; generator; - async; - (* TODO: add support for method predicates *) - predicate = None; - expression; returnType; typeParameters; - }) in - Ast.Class.(Body.Method (Loc.btwn start_loc end_loc, Method.({ - key; - value; - kind; - static; - decorators; - }))) + }) + ) env in + Loc.btwn start (fst value), Class.AbstractMethod.({ + key; + value; + static = static <> None; + }) - in fun env -> - let start_loc = Peek.loc env in - let decorators = decorator_list env in - let static = - Peek.ith_token ~i:1 env <> T_LPAREN && - Peek.ith_token ~i:1 env <> T_LESS_THAN && - Expect.maybe env T_STATIC in - let async = - Peek.ith_token ~i:1 env <> T_LPAREN && - Peek.ith_token ~i:1 env <> T_COLON && - Declaration.async env in - let generator = Declaration.generator env in - let variance = Declaration.variance env async generator in - let generator = match generator, variance with - | false, Some _ -> Declaration.generator env - | _ -> generator + in let class_method env start decors keywords generator key = + let (abstract, static, async) = keywords in + assert(abstract = None); + let kind, env = match static, key with + | None, Ast.Expression.Object.Property.Identifier (_, "constructor") + | None, Ast.Expression.Object.Property.Literal (_, { + Literal.value = Literal.String "constructor"; + _; + }) -> + Ast.Class.Method.Constructor, + env |> with_allow_super Super_prop_or_call + | _ -> + Ast.Class.Method.Method, + env |> with_allow_super Super_prop in - match async, generator, Peek.token env with - | false, false, T_IDENTIFIER { raw = "get"; _ } -> - let _, key = key ~class_body:true env in - (match Peek.token env with - | T_LESS_THAN - | T_COLON - | T_ASSIGN - | T_SEMICOLON - | T_LPAREN -> - init env start_loc decorators key async generator static variance + let func_loc = Peek.loc env in + let typeParameters = Type.type_parameter_declaration env in + let params = + let yield, await = match async, generator with + | Some _, true -> true, true (* proposal-async-iteration/#prod-AsyncGeneratorMethod *) + | Some _, false -> false, allow_await env (* #prod-AsyncMethod *) + | None, true -> true, false (* #prod-GeneratorMethod *) + | None, false -> false, false (* #prod-MethodDefinition *) + in + Declaration.function_params ~await ~yield env + in + let returnType = Type.annotation_opt env in + let _, body, strict = + Declaration.function_body env ~async:(async <> None) ~generator in + let simple = Declaration.is_simple_function_params params in + Declaration.strict_post_check env ~strict ~simple None params; + let end_loc, expression = Function.( + match body with + | BodyBlock (loc, _) -> loc, false + | BodyExpression (loc, _) -> loc, true) in + let value = Loc.btwn func_loc end_loc, Function.({ + id = None; + params; + body; + generator; + async = async <> None; + (* TODO: add support for method predicates *) + predicate = None; + expression; + returnType; + typeParameters; + }) in + Loc.btwn start end_loc, Ast.Class.Method.({ + key; + value; + kind; + static = static <> None; + decorators = decors; + }) + + in let class_property_value env static = with_loc (fun env -> + let typeAnnotation = Type.annotation_opt env in + let options = parse_options env in + let value = + if Peek.token env = T_ASSIGN then ( + if (static <> None) && options.esproposal_class_static_fields + || (static = None) && options.esproposal_class_instance_fields + then begin + Expect.token env T_ASSIGN; + Some (Parse.expression (env |> with_allow_super Super_prop)) + end else None + ) else None + in + begin if Expect.maybe env T_SEMICOLON then + () + else if Peek.token env == T_LBRACKET || Peek.token env == T_LPAREN then + error_unexpected env + end; + typeAnnotation, value) env + + in let init env start decors keywords generator variance k acc = + let (abstract, static, async) = keywords in + let key = match k with + | Some id -> + let _, name = id in + assert (List.mem name ["abstract";"static";"async";"get";"set"]); + Ast.Expression.Object.Property.Identifier id + | None -> + let id_loc = Peek.loc env in + Ast.Expression.Object.Property.(match key ~class_body:true env with + | _, (Identifier _ as key) + | _, (PrivateName _ as key) -> + key + | _, key -> + if abstract <> None then + error_at env (id_loc, Error.ExpectedIdentifier); + key) + in + if Peek.token env == T_PLING then ( + (* TODO: add support for optional class properties *) + error_unexpected env; + Eat.token env + ); + match Peek.token env with + | T_COLON + | T_ASSIGN + | T_SEMICOLON -> + if async <> None then error_unexpected env; + if generator then error_unexpected env; + let end_loc, (annotation, value) = class_property_value env static in + let loc = Loc.btwn start end_loc in + begin match key with + | Ast.Expression.Object.Property.PrivateName private_name -> + let p = loc, Ast.Class.PrivateField.({ + key = private_name; + value; + typeAnnotation = annotation; + static = static <> None; + variance; + }) in + Members.add_private_property env abstract p acc + | _ -> + let p = loc, Ast.Class.Property.({ + key; + value; + typeAnnotation = annotation; + static = static <> None; + variance; + }) in + Members.add_property env abstract p acc + end + | T_LESS_THAN + | T_LPAREN -> + begin match abstract, key with + | Some _, Ast.Expression.Object.Property.Identifier key -> + let m = class_abstract_method env start keywords generator key in + Members.add_abstract_method env variance m acc + | Some _, Ast.Expression.Object.Property.PrivateName (_, key) -> + let m = class_abstract_method env start keywords generator key in + error_at env (fst m, Error.AbstractPrivate); + Members.add_abstract_method env variance m acc | _ -> - error_unsupported_variance env variance; - get env start_loc decorators static) - | false, false, T_IDENTIFIER { raw = "set"; _ } -> - let _, key = key ~class_body:true env in - (match Peek.token env with - | T_LESS_THAN - | T_COLON - | T_ASSIGN - | T_SEMICOLON - | T_LPAREN -> - init env start_loc decorators key async generator static variance + (* Given an abstract method with some non-identifier key, the + `AbstractNonidentifier` error has already been handled. Parse + such an abstract method as a non-abstract method alongside + non-abstract methods. *) + let m = class_method env start decors keywords generator key in + Members.add_method env variance m acc + end + | _ -> + error_unexpected env; + Eat.token env; + acc + + in let is_prior_init_key env = + match Peek.token env with + | T_LESS_THAN | T_LPAREN + | T_PLING | T_COLON + | T_ASSIGN + | T_SEMICOLON -> + true + | _ -> false + + in let prelude_keywords env decors = + let id_opt name = function + | Some loc -> Some (loc, name) + | None -> None + in + let loc = Peek.loc env in + let abstract = if Expect.maybe env T_ABSTRACT then Some loc else None in + if is_prior_init_key env then + ((None, None, None), id_opt "abstract" abstract) + else begin + begin match decors, abstract with + | _::_, Some loc -> + error_at env (loc, Error.DecoratorOnAbstract) + | _ -> () + end; + let loc = Peek.loc env in + let static = if Expect.maybe env T_STATIC then Some loc else None in + if is_prior_init_key env then + ((abstract, None, None), id_opt "static" static) + else + let loc = Peek.loc env in + let async = if Expect.maybe env T_ASYNC then Some loc else None in + if is_prior_init_key env then + ((abstract, static, None), id_opt "async" async) + else + ((abstract, static, async), None) + end + + in fun env acc -> + let start = Peek.loc env in + let decors = decorator_list env in + let (keywords, key) = prelude_keywords env decors in + match key with + | Some _ -> + let generator = false in + let variance = None in + init env start decors keywords generator variance key acc + | None -> + let (abstract, static, async) = keywords in + let generator = Declaration.generator env in + let variance = Declaration.variance env (async <> None) generator in + let generator = match generator, variance with + | false, Some _ -> Declaration.generator env + | _ -> generator + in + match Peek.token env with + | T_IDENTIFIER { raw = "get" | "set" as name; _ } -> + let name_loc = Peek.loc env in + Eat.token env; + begin match name, is_prior_init_key env with + | "get", false -> + if (async <> None) || generator then error_unexpected env; + let m = class_get env start decors static in + Members.add_getter env abstract variance m acc + | "set", false -> + if (async <> None) || generator then error_unexpected env; + let m = class_set env start decors static in + Members.add_setter env abstract variance m acc + | _ -> + let key = Some (name_loc, name) in + init env start decors keywords generator variance key acc + end | _ -> - error_unsupported_variance env variance; - set env start_loc decorators static) - | _, _, _ -> - let _, key = key ~class_body:true env in - init env start_loc decorators key async generator static variance + init env start decors keywords generator variance key acc let class_declaration env decorators = (* 10.2.1 says all parts of a class definition are strict *) let env = env |> with_strict true in let start_loc = Peek.loc env in let decorators = decorators @ (decorator_list env) in + ignore (Expect.maybe env T_ABSTRACT); Expect.token env T_CLASS; let tmp_env = env |> with_no_let true in let id = ( diff --git a/src/parser/parse_error.ml b/src/parser/parse_error.ml index 70229dcd1bb..f2a686cd656 100644 --- a/src/parser/parse_error.ml +++ b/src/parser/parse_error.ml @@ -18,6 +18,7 @@ type t = | UnexpectedSuperCall | UnexpectedEOS | UnexpectedVariance + | UnexpectedAbstract | UnexpectedStatic | UnexpectedTypeAlias | UnexpectedOpaqueTypeAlias @@ -107,6 +108,20 @@ type t = | LiteralShorthandProperty | ComputedShorthandProperty | MethodInDestructuring + | PrivateGetter + | PrivateSetter + | ExpectedIdentifier + | AbstractConstructor + | AbstractPrivate + | AbstractProperty + | AbstractIndexer + | AbstractCall + | AbstractGetter + | AbstractSetter + | AbstractStaticName + | DecoratorOnAbstract + | DuplicateAbstractMethods of string + | ImmediateAbstract of string exception Error of (Loc.t * t) list @@ -131,6 +146,7 @@ module PP = | UnexpectedSuperCall -> "`super()` is only valid in a class constructor" | UnexpectedEOS -> "Unexpected end of input" | UnexpectedVariance -> "Unexpected variance sigil" + | UnexpectedAbstract -> "Unexpected abstract modifier" | UnexpectedStatic -> "Unexpected static modifier" | UnexpectedTypeAlias -> "Type aliases are not allowed in untyped mode" | UnexpectedOpaqueTypeAlias -> "Opaque type aliases are not allowed in untyped mode" @@ -270,4 +286,19 @@ module PP = | LiteralShorthandProperty -> "Literals cannot be used as shorthand properties." | ComputedShorthandProperty -> "Computed properties must have a value." | MethodInDestructuring -> "Object pattern can't contain methods" + | PrivateGetter -> "Private getters are not allowed." + | PrivateSetter -> "Private setters are not allowed." + | ExpectedIdentifier -> "Expected an identifier." + | AbstractConstructor -> "Abstract class constructors are not allowed." + | AbstractPrivate -> "Abstract privates are not allowed." + | AbstractProperty -> "Abstract properties are not allowed." + | AbstractIndexer -> "Abstract indexers are not allowed." + | AbstractCall -> "Abstract call properties are not allowed." + | AbstractGetter -> "Abstract getters are not allowed." + | AbstractSetter -> "Abstract setters are not allowed." + | AbstractStaticName -> "Abstract static `name` methods are not allowed." + | DecoratorOnAbstract -> "Decorator(s) not allowed on an abstract." + | DuplicateAbstractMethods name -> + "Abstract methods may only be declared once. `" ^ name ^ "` is declared more than once." + | ImmediateAbstract name -> "Abstract method `" ^ name ^ "` is implemented locally." end diff --git a/src/parser/parser_common.ml b/src/parser/parser_common.ml index 6c6120c404a..8d067648a6e 100644 --- a/src/parser/parser_common.ml +++ b/src/parser/parser_common.ml @@ -105,6 +105,7 @@ let identifier_name env = | T_TRUE -> "true" | T_FALSE -> "false" (* Flow-specific stuff *) + | T_ABSTRACT -> "abstract" | T_DECLARE -> "declare" | T_TYPE -> "type" | T_OPAQUE -> "opaque" diff --git a/src/parser/parser_env.ml b/src/parser/parser_env.ml index e0789fb186b..3ee41a8c69e 100644 --- a/src/parser/parser_env.ml +++ b/src/parser/parser_env.ml @@ -528,6 +528,7 @@ module Peek = struct | T_NUMBER_SINGLETON_TYPE _ (* identifier-ish *) + | T_ABSTRACT | T_ASYNC | T_AWAIT | T_BREAK @@ -680,6 +681,7 @@ module Peek = struct let is_class env = match token env with | T_CLASS + | T_ABSTRACT | T_AT -> true | _ -> false end diff --git a/src/parser/statement_parser.ml b/src/parser/statement_parser.ml index bdde6bd9c01..eebb471e2c4 100644 --- a/src/parser/statement_parser.ml +++ b/src/parser/statement_parser.ml @@ -613,7 +613,7 @@ module Statement Expect.token env T_EXTENDS; supers env [] end else [] in - let body = Type._object ~allow_static:false env in + let body = Type._object ~allow_abstract:false ~allow_static:false env in Statement.Interface.({ id; typeParameters; @@ -646,7 +646,8 @@ module Statement mixins env acc | _ -> List.rev acc - (* This is identical to `interface`, except that mixins are allowed *) + (* This is identical to `interface`, except that mixins and abstracts are + allowed. *) in fun env -> let env = env |> with_strict true in Expect.token env T_CLASS; @@ -657,7 +658,7 @@ module Statement | T_IDENTIFIER { raw = "mixins"; _ } -> Eat.token env; mixins env [] | _ -> [] in - let body = Type._object ~allow_static:true env in + let body = Type._object ~allow_abstract:true ~allow_static:true env in Statement.DeclareClass.({ id; typeParameters; @@ -668,6 +669,7 @@ module Statement and declare_class_statement env = with_loc (fun env -> Expect.token env T_DECLARE; + ignore (Expect.maybe env T_ABSTRACT); let fn = declare_class env in Statement.DeclareClass fn ) env @@ -684,6 +686,8 @@ module Statement let loc = Loc.btwn start_sig_loc end_loc in let typeAnnotation = loc, Ast.Type.(Function {Function. params; + async = false; + generator = false; returnType; typeParameters; }) in @@ -834,6 +838,7 @@ module Statement then error env Error.UnexpectedTypeDeclaration; (* eventually, just emit a wrapper AST node *) (match Peek.ith_token ~i:1 env with + | T_ABSTRACT | T_CLASS -> declare_class_statement env | T_INTERFACE -> diff --git a/src/parser/test/custom_ast_types.js b/src/parser/test/custom_ast_types.js index 9b0538b049d..ffbfc9cff35 100644 --- a/src/parser/test/custom_ast_types.js +++ b/src/parser/test/custom_ast_types.js @@ -232,3 +232,21 @@ def('Import') def('CallExpression') .field('callee', or(def('Expression'), def('Import'))); + +def("AbstractMethodDefinition") + .bases("Declaration") + .build("key", "value", "static") + .field("key", def("Identifier")) + .field("value", def("FunctionTypeAnnotation")) + .field("static", Boolean); + +var ClassBodyElement = or( + def("AbstractMethodDefinition"), + def("MethodDefinition"), + def("VariableDeclarator"), + def("ClassPropertyDefinition"), + def("ClassProperty") +); + +def("ClassBody") + .field("body", [ClassBodyElement]); diff --git a/src/parser/test/esprima_test_runner.js b/src/parser/test/esprima_test_runner.js index 0950f8f2942..ea996665daf 100644 --- a/src/parser/test/esprima_test_runner.js +++ b/src/parser/test/esprima_test_runner.js @@ -200,8 +200,13 @@ function handleSpecialObjectCompare(esprima, flow, env) { case 'ObjectTypeAnnotation': esprima.exact = esprima.exact || false; break; + case 'FunctionTypeAnnotation': + esprima.async = esprima.async || false; + esprima.generator = esprima.generator || false; + break; case 'ObjectTypeProperty': esprima.kind = "init"; // esprima-fb doesn't support getters/setters + esprima.abstract = esprima.abstract || false; esprima.static = esprima.static || false; break; case 'ObjectTypeIndexer': diff --git a/src/parser/test/flow/ES6/modules/migrated_0007.tree.json b/src/parser/test/flow/ES6/modules/migrated_0007.tree.json index a06702bba5b..924eca15652 100644 --- a/src/parser/test/flow/ES6/modules/migrated_0007.tree.json +++ b/src/parser/test/flow/ES6/modules/migrated_0007.tree.json @@ -45,6 +45,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/abstract_class/abstract_named.js b/src/parser/test/flow/abstract_class/abstract_named.js new file mode 100644 index 00000000000..ddace6a6d8b --- /dev/null +++ b/src/parser/test/flow/abstract_class/abstract_named.js @@ -0,0 +1,4 @@ +class AbstractNamedMethod { abstract(): void {} } +class StaticAbstractNamedMethod { static abstract(): void {} } +declare class AbstractNamedMethodDecl { abstract(): void; } +declare class StaticAbstractNamedMethodDecl { static abstract(): void; } diff --git a/src/parser/test/flow/abstract_class/abstract_named.tree.json b/src/parser/test/flow/abstract_class/abstract_named.tree.json new file mode 100644 index 00000000000..e547047c289 --- /dev/null +++ b/src/parser/test/flow/abstract_class/abstract_named.tree.json @@ -0,0 +1,266 @@ +{ + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":4,"column":74}}, + "range":[0,299], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":74}}, + "range":[0,74], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":33}}, + "range":[14,33], + "name":"AbstractNamedMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":44},"end":{"line":1,"column":74}}, + "range":[44,74], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":53},"end":{"line":1,"column":72}}, + "range":[53,72], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":53},"end":{"line":1,"column":61}}, + "range":[53,61], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":1,"column":61},"end":{"line":1,"column":72}}, + "range":[61,72], + "id":null, + "params":[], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":1,"column":70},"end":{"line":1,"column":72}}, + "range":[70,72], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":63},"end":{"line":1,"column":69}}, + "range":[63,69], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":65},"end":{"line":1,"column":69}}, + "range":[65,69] + } + }, + "typeParameters":null + }, + "kind":"method", + "static":false, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":74}}, + "range":[75,149], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":14},"end":{"line":2,"column":39}}, + "range":[89,114], + "name":"StaticAbstractNamedMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":2,"column":44},"end":{"line":2,"column":74}}, + "range":[119,149], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":2,"column":46},"end":{"line":2,"column":72}}, + "range":[121,147], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":53},"end":{"line":2,"column":61}}, + "range":[128,136], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":2,"column":61},"end":{"line":2,"column":72}}, + "range":[136,147], + "id":null, + "params":[], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":2,"column":70},"end":{"line":2,"column":72}}, + "range":[145,147], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":63},"end":{"line":2,"column":69}}, + "range":[138,144], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":65},"end":{"line":2,"column":69}}, + "range":[140,144] + } + }, + "typeParameters":null + }, + "kind":"method", + "static":true, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":74}}, + "range":[150,224], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":14},"end":{"line":3,"column":37}}, + "range":[164,187], + "name":"AbstractNamedMethodDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":44},"end":{"line":3,"column":74}}, + "range":[194,224], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":3,"column":53},"end":{"line":3,"column":69}}, + "range":[203,219], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":53},"end":{"line":3,"column":61}}, + "range":[203,211], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":53},"end":{"line":3,"column":69}}, + "range":[203,219], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":65},"end":{"line":3,"column":69}}, + "range":[215,219] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":74}}, + "range":[225,299], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":14},"end":{"line":4,"column":43}}, + "range":[239,268], + "name":"StaticAbstractNamedMethodDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":44},"end":{"line":4,"column":74}}, + "range":[269,299], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":4,"column":46},"end":{"line":4,"column":69}}, + "range":[271,294], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":53},"end":{"line":4,"column":61}}, + "range":[278,286], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":46},"end":{"line":4,"column":69}}, + "range":[271,294], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":65},"end":{"line":4,"column":69}}, + "range":[290,294] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":false, + "static":true, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + } + ], + "comments":[] +} diff --git a/src/parser/test/flow/abstract_class/async.js b/src/parser/test/flow/abstract_class/async.js new file mode 100644 index 00000000000..33d96978866 --- /dev/null +++ b/src/parser/test/flow/abstract_class/async.js @@ -0,0 +1,10 @@ +class AsyncNamedMethod { abstract async(): void; } +declare class AsyncNamedMethodDecl { abstract async(): void; } +class StaticAsyncNamedMethod { abstract static async(): void; } +declare class StaticAsyncNamedMethodDecl { abstract static async(): void; } + +class AbstractAsyncMethod { abstract async m(): void; } +class StaticAbstractAsyncMethod { abstract static async m(): void; } + +class AbstractAsyncProperty { abstract async p: void; } //Error +class StaticAbstractAsyncProperty { abstract static async p: void; } //Error diff --git a/src/parser/test/flow/abstract_class/async.tree.json b/src/parser/test/flow/abstract_class/async.tree.json new file mode 100644 index 00000000000..350dc959997 --- /dev/null +++ b/src/parser/test/flow/abstract_class/async.tree.json @@ -0,0 +1,477 @@ +{ + "errors":[ + { + "loc":{"source":null,"start":{"line":9,"column":59},"end":{"line":9,"column":60}}, + "message":"Unexpected token :" + }, + { + "loc":{"source":null,"start":{"line":9,"column":36},"end":{"line":9,"column":66}}, + "message":"Abstract properties are not allowed." + }, + { + "loc":{"source":null,"start":{"line":10,"column":59},"end":{"line":10,"column":60}}, + "message":"Unexpected token :" + }, + { + "loc":{"source":null,"start":{"line":10,"column":36},"end":{"line":10,"column":66}}, + "message":"Abstract properties are not allowed." + } + ], + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":10,"column":68}}, + "range":[0,589], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":75}}, + "range":[0,75], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":30}}, + "range":[14,30], + "name":"AsyncNamedMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":41},"end":{"line":1,"column":75}}, + "range":[41,75], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":43},"end":{"line":1,"column":73}}, + "range":[43,73], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":59},"end":{"line":1,"column":64}}, + "range":[59,64], + "name":"async", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":64},"end":{"line":1,"column":73}}, + "range":[64,73], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":68},"end":{"line":1,"column":72}}, + "range":[68,72] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":75}}, + "range":[76,151], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":14},"end":{"line":2,"column":34}}, + "range":[90,110], + "name":"AsyncNamedMethodDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":41},"end":{"line":2,"column":75}}, + "range":[117,151], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":2,"column":43},"end":{"line":2,"column":72}}, + "range":[119,148], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":59},"end":{"line":2,"column":64}}, + "range":[135,140], + "name":"async", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":43},"end":{"line":2,"column":72}}, + "range":[119,148], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":68},"end":{"line":2,"column":72}}, + "range":[144,148] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":75}}, + "range":[152,227], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":14},"end":{"line":3,"column":36}}, + "range":[166,188], + "name":"StaticAsyncNamedMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":3,"column":41},"end":{"line":3,"column":75}}, + "range":[193,227], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":3,"column":43},"end":{"line":3,"column":73}}, + "range":[195,225], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":59},"end":{"line":3,"column":64}}, + "range":[211,216], + "name":"async", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":64},"end":{"line":3,"column":73}}, + "range":[216,225], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":68},"end":{"line":3,"column":72}}, + "range":[220,224] + }, + "rest":null, + "typeParameters":null + }, + "static":true + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":75}}, + "range":[228,303], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":14},"end":{"line":4,"column":40}}, + "range":[242,268], + "name":"StaticAsyncNamedMethodDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":41},"end":{"line":4,"column":75}}, + "range":[269,303], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":4,"column":43},"end":{"line":4,"column":72}}, + "range":[271,300], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":59},"end":{"line":4,"column":64}}, + "range":[287,292], + "name":"async", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":43},"end":{"line":4,"column":72}}, + "range":[271,300], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":68},"end":{"line":4,"column":72}}, + "range":[296,300] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":true, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":6,"column":0},"end":{"line":6,"column":68}}, + "range":[305,373], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":6},"end":{"line":6,"column":25}}, + "range":[311,330], + "name":"AbstractAsyncMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":6,"column":32},"end":{"line":6,"column":68}}, + "range":[337,373], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":6,"column":34},"end":{"line":6,"column":66}}, + "range":[339,371], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":56},"end":{"line":6,"column":57}}, + "range":[361,362], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":57},"end":{"line":6,"column":66}}, + "range":[362,371], + "params":[], + "async":true, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":61},"end":{"line":6,"column":65}}, + "range":[366,370] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":7,"column":0},"end":{"line":7,"column":68}}, + "range":[374,442], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":6},"end":{"line":7,"column":31}}, + "range":[380,405], + "name":"StaticAbstractAsyncMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":7,"column":32},"end":{"line":7,"column":68}}, + "range":[406,442], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":7,"column":34},"end":{"line":7,"column":66}}, + "range":[408,440], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":56},"end":{"line":7,"column":57}}, + "range":[430,431], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":57},"end":{"line":7,"column":66}}, + "range":[431,440], + "params":[], + "async":true, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":61},"end":{"line":7,"column":65}}, + "range":[435,439] + }, + "rest":null, + "typeParameters":null + }, + "static":true + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":9,"column":0},"end":{"line":9,"column":68}}, + "range":[444,512], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":6},"end":{"line":9,"column":27}}, + "range":[450,471], + "name":"AbstractAsyncProperty", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":9,"column":34},"end":{"line":9,"column":68}}, + "range":[478,512], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":9,"column":36},"end":{"line":9,"column":66}}, + "range":[480,510], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":58},"end":{"line":9,"column":59}}, + "range":[502,503], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":59},"end":{"line":9,"column":65}}, + "range":[503,509], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":61},"end":{"line":9,"column":65}}, + "range":[505,509] + } + }, + "computed":false, + "static":false, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":10,"column":0},"end":{"line":10,"column":68}}, + "range":[521,589], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":10,"column":6},"end":{"line":10,"column":33}}, + "range":[527,554], + "name":"StaticAbstractAsyncProperty", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":10,"column":34},"end":{"line":10,"column":68}}, + "range":[555,589], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":10,"column":36},"end":{"line":10,"column":66}}, + "range":[557,587], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":10,"column":58},"end":{"line":10,"column":59}}, + "range":[579,580], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":10,"column":59},"end":{"line":10,"column":65}}, + "range":[580,586], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":10,"column":61},"end":{"line":10,"column":65}}, + "range":[582,586] + } + }, + "computed":false, + "static":true, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + } + ], + "comments":[ + { + "type":"Line", + "loc":{"source":null,"start":{"line":9,"column":69},"end":{"line":9,"column":76}}, + "range":[513,520], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":10,"column":69},"end":{"line":10,"column":76}}, + "range":[590,597], + "value":"Error" + } + ] +} diff --git a/src/parser/test/flow/abstract_class/class_prefix.js b/src/parser/test/flow/abstract_class/class_prefix.js new file mode 100644 index 00000000000..bca2c2eebf2 --- /dev/null +++ b/src/parser/test/flow/abstract_class/class_prefix.js @@ -0,0 +1,2 @@ +abstract class PrefixedClass {} +declare abstract class PrefixedAbstractClass {} diff --git a/src/parser/test/flow/abstract_class/class_prefix.tree.json b/src/parser/test/flow/abstract_class/class_prefix.tree.json new file mode 100644 index 00000000000..660734df736 --- /dev/null +++ b/src/parser/test/flow/abstract_class/class_prefix.tree.json @@ -0,0 +1,56 @@ +{ + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":2,"column":47}}, + "range":[0,79], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":31}}, + "range":[0,31], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":15},"end":{"line":1,"column":28}}, + "range":[15,28], + "name":"PrefixedClass", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":31}}, + "range":[29,31], + "body":[] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":47}}, + "range":[32,79], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":23},"end":{"line":2,"column":44}}, + "range":[55,76], + "name":"PrefixedAbstractClass", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":45},"end":{"line":2,"column":47}}, + "range":[77,79], + "exact":false, + "properties":[], + "indexers":[], + "callProperties":[] + }, + "extends":[] + } + ], + "comments":[] +} diff --git a/src/parser/test/flow/abstract_class/constructor.js b/src/parser/test/flow/abstract_class/constructor.js new file mode 100644 index 00000000000..4a3fe8b5d06 --- /dev/null +++ b/src/parser/test/flow/abstract_class/constructor.js @@ -0,0 +1,4 @@ +class AbstractConstructor { abstract constructor(): void; } // Error, abstract constructor is not allowed +class AbstractStaticConstructor { abstract static constructor(): void; } // Error, abstract constructor is not allowed +declare class AbstractConstructorDecl { abstract constructor(): void; } // Error, abstract constructor is not allowed +declare class AbstractStaticConstructorDecl { abstract static constructor(): void; } // Error, abstract constructor is not allowed diff --git a/src/parser/test/flow/abstract_class/constructor.tree.json b/src/parser/test/flow/abstract_class/constructor.tree.json new file mode 100644 index 00000000000..1d538b5debe --- /dev/null +++ b/src/parser/test/flow/abstract_class/constructor.tree.json @@ -0,0 +1,277 @@ +{ + "errors":[ + { + "loc":{"source":null,"start":{"line":1,"column":46},"end":{"line":1,"column":82}}, + "message":"Abstract class constructors are not allowed." + }, + { + "loc":{"source":null,"start":{"line":2,"column":46},"end":{"line":2,"column":82}}, + "message":"Abstract class constructors are not allowed." + }, + { + "loc":{"source":null,"start":{"line":3,"column":46},"end":{"line":3,"column":81}}, + "message":"Abstract class constructors are not allowed." + }, + { + "loc":{"source":null,"start":{"line":4,"column":46},"end":{"line":4,"column":81}}, + "message":"Abstract class constructors are not allowed." + } + ], + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":4,"column":84}}, + "range":[0,477], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":84}}, + "range":[0,84], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":33}}, + "range":[14,33], + "name":"AbstractConstructor", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":44},"end":{"line":1,"column":84}}, + "range":[44,84], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":46},"end":{"line":1,"column":82}}, + "range":[46,82], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":62},"end":{"line":1,"column":73}}, + "range":[62,73], + "name":"constructor", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":73},"end":{"line":1,"column":82}}, + "range":[73,82], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":77},"end":{"line":1,"column":81}}, + "range":[77,81] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":84}}, + "range":[131,215], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":14},"end":{"line":2,"column":39}}, + "range":[145,170], + "name":"AbstractStaticConstructor", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":2,"column":44},"end":{"line":2,"column":84}}, + "range":[175,215], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":2,"column":46},"end":{"line":2,"column":82}}, + "range":[177,213], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":62},"end":{"line":2,"column":73}}, + "range":[193,204], + "name":"constructor", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":73},"end":{"line":2,"column":82}}, + "range":[204,213], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":77},"end":{"line":2,"column":81}}, + "range":[208,212] + }, + "rest":null, + "typeParameters":null + }, + "static":true + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":84}}, + "range":[262,346], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":14},"end":{"line":3,"column":37}}, + "range":[276,299], + "name":"AbstractConstructorDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":44},"end":{"line":3,"column":84}}, + "range":[306,346], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":3,"column":46},"end":{"line":3,"column":81}}, + "range":[308,343], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":62},"end":{"line":3,"column":73}}, + "range":[324,335], + "name":"constructor", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":46},"end":{"line":3,"column":81}}, + "range":[308,343], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":77},"end":{"line":3,"column":81}}, + "range":[339,343] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":84}}, + "range":[393,477], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":14},"end":{"line":4,"column":43}}, + "range":[407,436], + "name":"AbstractStaticConstructorDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":44},"end":{"line":4,"column":84}}, + "range":[437,477], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":4,"column":46},"end":{"line":4,"column":81}}, + "range":[439,474], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":62},"end":{"line":4,"column":73}}, + "range":[455,466], + "name":"constructor", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":46},"end":{"line":4,"column":81}}, + "range":[439,474], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":77},"end":{"line":4,"column":81}}, + "range":[470,474] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":true, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + } + ], + "comments":[ + { + "type":"Line", + "loc":{"source":null,"start":{"line":1,"column":85},"end":{"line":1,"column":130}}, + "range":[85,130], + "value":" Error, abstract constructor is not allowed" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":2,"column":85},"end":{"line":2,"column":130}}, + "range":[216,261], + "value":" Error, abstract constructor is not allowed" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":3,"column":85},"end":{"line":3,"column":130}}, + "range":[347,392], + "value":" Error, abstract constructor is not allowed" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":4,"column":85},"end":{"line":4,"column":130}}, + "range":[478,523], + "value":" Error, abstract constructor is not allowed" + } + ] +} diff --git a/src/parser/test/flow/abstract_class/decorator.js b/src/parser/test/flow/abstract_class/decorator.js new file mode 100644 index 00000000000..c37cb8be67b --- /dev/null +++ b/src/parser/test/flow/abstract_class/decorator.js @@ -0,0 +1,5 @@ +class DecoratedAbstractMethod { @decorator abstract m(): void; } +class StaticDecoratedAbstractMethod { @decorator abstract static m(): void; } + +class DecoratedAbstractProperty { @decorator abstract p: void; } +class StaticDecoratedAbstractProperty { @decorator abstract static p: void; } diff --git a/src/parser/test/flow/abstract_class/decorator.options.json b/src/parser/test/flow/abstract_class/decorator.options.json new file mode 100644 index 00000000000..f8fe3866e97 --- /dev/null +++ b/src/parser/test/flow/abstract_class/decorator.options.json @@ -0,0 +1,3 @@ +{ + "esproposal_decorators": true +} diff --git a/src/parser/test/flow/abstract_class/decorator.tree.json b/src/parser/test/flow/abstract_class/decorator.tree.json new file mode 100644 index 00000000000..5372cfde758 --- /dev/null +++ b/src/parser/test/flow/abstract_class/decorator.tree.json @@ -0,0 +1,246 @@ +{ + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":5,"column":77}}, + "range":[0,312], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":77}}, + "range":[0,77], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":29}}, + "range":[6,29], + "name":"DecoratedAbstractMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":36},"end":{"line":1,"column":77}}, + "range":[36,77], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":38},"end":{"line":1,"column":75}}, + "range":[38,75], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":65},"end":{"line":1,"column":66}}, + "range":[65,66], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":66},"end":{"line":1,"column":75}}, + "range":[66,75], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":70},"end":{"line":1,"column":74}}, + "range":[70,74] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":77}}, + "range":[78,155], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":6},"end":{"line":2,"column":35}}, + "range":[84,113], + "name":"StaticDecoratedAbstractMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":2,"column":36},"end":{"line":2,"column":77}}, + "range":[114,155], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":2,"column":38},"end":{"line":2,"column":75}}, + "range":[116,153], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":65},"end":{"line":2,"column":66}}, + "range":[143,144], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":66},"end":{"line":2,"column":75}}, + "range":[144,153], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":70},"end":{"line":2,"column":74}}, + "range":[148,152] + }, + "rest":null, + "typeParameters":null + }, + "static":true + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":77}}, + "range":[157,234], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":6},"end":{"line":4,"column":31}}, + "range":[163,188], + "name":"DecoratedAbstractProperty", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":4,"column":38},"end":{"line":4,"column":77}}, + "range":[195,234], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":4,"column":40},"end":{"line":4,"column":75}}, + "range":[197,232], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":67},"end":{"line":4,"column":68}}, + "range":[224,225], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":68},"end":{"line":4,"column":74}}, + "range":[225,231], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":70},"end":{"line":4,"column":74}}, + "range":[227,231] + } + }, + "computed":false, + "static":false, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":5,"column":0},"end":{"line":5,"column":77}}, + "range":[235,312], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":5,"column":6},"end":{"line":5,"column":37}}, + "range":[241,272], + "name":"StaticDecoratedAbstractProperty", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":5,"column":38},"end":{"line":5,"column":77}}, + "range":[273,312], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":5,"column":40},"end":{"line":5,"column":75}}, + "range":[275,310], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":5,"column":67},"end":{"line":5,"column":68}}, + "range":[302,303], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":5,"column":68},"end":{"line":5,"column":74}}, + "range":[303,309], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":5,"column":70},"end":{"line":5,"column":74}}, + "range":[305,309] + } + }, + "computed":false, + "static":true, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + } + ], + "comments":[], + "errors":[ + { + "loc":{"source":null,"start":{"line":1,"column":49},"end":{"line":1,"column":57}}, + "message":"Decorator(s) not allowed on an abstract." + }, + { + "loc":{"source":null,"start":{"line":2,"column":49},"end":{"line":2,"column":57}}, + "message":"Decorator(s) not allowed on an abstract." + }, + { + "loc":{"source":null,"start":{"line":4,"column":51},"end":{"line":4,"column":59}}, + "message":"Decorator(s) not allowed on an abstract." + }, + { + "loc":{"source":null,"start":{"line":4,"column":40},"end":{"line":4,"column":75}}, + "message":"Abstract properties are not allowed." + }, + { + "loc":{"source":null,"start":{"line":5,"column":51},"end":{"line":5,"column":59}}, + "message":"Decorator(s) not allowed on an abstract." + }, + { + "loc":{"source":null,"start":{"line":5,"column":40},"end":{"line":5,"column":75}}, + "message":"Abstract properties are not allowed." + } + ] +} diff --git a/src/parser/test/flow/abstract_class/duplicate.js b/src/parser/test/flow/abstract_class/duplicate.js new file mode 100644 index 00000000000..51e5a0fd9ad --- /dev/null +++ b/src/parser/test/flow/abstract_class/duplicate.js @@ -0,0 +1,4 @@ +class Duplicate { abstract m(): void; abstract m(): void; } //Error +class StaticDuplicate { abstract static m(): void; abstract static m(): void; } //Error +class DuplicateDecl { abstract m(): void; abstract m(): void; } //Error +class StaticDuplicateDecl { abstract static m(): void; abstract static m(): void; } //Error diff --git a/src/parser/test/flow/abstract_class/duplicate.tree.json b/src/parser/test/flow/abstract_class/duplicate.tree.json new file mode 100644 index 00000000000..1bf6cc67f56 --- /dev/null +++ b/src/parser/test/flow/abstract_class/duplicate.tree.json @@ -0,0 +1,383 @@ +{ + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":4,"column":83}}, + "range":[0,359], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":83}}, + "range":[0,83], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":15}}, + "range":[6,15], + "name":"Duplicate", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":26},"end":{"line":1,"column":83}}, + "range":[26,83], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":28},"end":{"line":1,"column":54}}, + "range":[28,54], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":44},"end":{"line":1,"column":45}}, + "range":[44,45], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":45},"end":{"line":1,"column":54}}, + "range":[45,54], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":49},"end":{"line":1,"column":53}}, + "range":[49,53] + }, + "rest":null, + "typeParameters":null + }, + "static":false + }, + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":55},"end":{"line":1,"column":81}}, + "range":[55,81], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":71},"end":{"line":1,"column":72}}, + "range":[71,72], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":72},"end":{"line":1,"column":81}}, + "range":[72,81], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":76},"end":{"line":1,"column":80}}, + "range":[76,80] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":83}}, + "range":[92,175], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":6},"end":{"line":2,"column":21}}, + "range":[98,113], + "name":"StaticDuplicate", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":2,"column":26},"end":{"line":2,"column":83}}, + "range":[118,175], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":2,"column":28},"end":{"line":2,"column":54}}, + "range":[120,146], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":44},"end":{"line":2,"column":45}}, + "range":[136,137], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":45},"end":{"line":2,"column":54}}, + "range":[137,146], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":49},"end":{"line":2,"column":53}}, + "range":[141,145] + }, + "rest":null, + "typeParameters":null + }, + "static":true + }, + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":2,"column":55},"end":{"line":2,"column":81}}, + "range":[147,173], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":71},"end":{"line":2,"column":72}}, + "range":[163,164], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":72},"end":{"line":2,"column":81}}, + "range":[164,173], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":76},"end":{"line":2,"column":80}}, + "range":[168,172] + }, + "rest":null, + "typeParameters":null + }, + "static":true + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":83}}, + "range":[184,267], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":6},"end":{"line":3,"column":19}}, + "range":[190,203], + "name":"DuplicateDecl", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":3,"column":26},"end":{"line":3,"column":83}}, + "range":[210,267], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":3,"column":28},"end":{"line":3,"column":54}}, + "range":[212,238], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":44},"end":{"line":3,"column":45}}, + "range":[228,229], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":45},"end":{"line":3,"column":54}}, + "range":[229,238], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":49},"end":{"line":3,"column":53}}, + "range":[233,237] + }, + "rest":null, + "typeParameters":null + }, + "static":false + }, + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":3,"column":55},"end":{"line":3,"column":81}}, + "range":[239,265], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":71},"end":{"line":3,"column":72}}, + "range":[255,256], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":72},"end":{"line":3,"column":81}}, + "range":[256,265], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":76},"end":{"line":3,"column":80}}, + "range":[260,264] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":83}}, + "range":[276,359], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":6},"end":{"line":4,"column":25}}, + "range":[282,301], + "name":"StaticDuplicateDecl", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":4,"column":26},"end":{"line":4,"column":83}}, + "range":[302,359], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":4,"column":28},"end":{"line":4,"column":54}}, + "range":[304,330], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":44},"end":{"line":4,"column":45}}, + "range":[320,321], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":45},"end":{"line":4,"column":54}}, + "range":[321,330], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":49},"end":{"line":4,"column":53}}, + "range":[325,329] + }, + "rest":null, + "typeParameters":null + }, + "static":true + }, + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":4,"column":55},"end":{"line":4,"column":81}}, + "range":[331,357], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":71},"end":{"line":4,"column":72}}, + "range":[347,348], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":72},"end":{"line":4,"column":81}}, + "range":[348,357], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":76},"end":{"line":4,"column":80}}, + "range":[352,356] + }, + "rest":null, + "typeParameters":null + }, + "static":true + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + } + ], + "comments":[ + { + "type":"Line", + "loc":{"source":null,"start":{"line":1,"column":84},"end":{"line":1,"column":91}}, + "range":[84,91], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":2,"column":84},"end":{"line":2,"column":91}}, + "range":[176,183], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":3,"column":84},"end":{"line":3,"column":91}}, + "range":[268,275], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":4,"column":84},"end":{"line":4,"column":91}}, + "range":[360,367], + "value":"Error" + } + ], + "errors":[ + { + "loc":{"source":null,"start":{"line":1,"column":55},"end":{"line":1,"column":81}}, + "message":"Abstract methods may only be declared once. `m` is declared more than once." + }, + { + "loc":{"source":null,"start":{"line":2,"column":55},"end":{"line":2,"column":81}}, + "message":"Abstract methods may only be declared once. `m` is declared more than once." + }, + { + "loc":{"source":null,"start":{"line":3,"column":55},"end":{"line":3,"column":81}}, + "message":"Abstract methods may only be declared once. `m` is declared more than once." + }, + { + "loc":{"source":null,"start":{"line":4,"column":55},"end":{"line":4,"column":81}}, + "message":"Abstract methods may only be declared once. `m` is declared more than once." + } + ] +} diff --git a/src/parser/test/flow/abstract_class/generator.js b/src/parser/test/flow/abstract_class/generator.js new file mode 100644 index 00000000000..77b797c4f1c --- /dev/null +++ b/src/parser/test/flow/abstract_class/generator.js @@ -0,0 +1,5 @@ +class AbstractAsyncGenerator { abstract async *m(): void; } +class StaticAbstractAsyncGenerator { abstract static async *m(): void; } + +class AbstractAsyncGeneratorProperty { abstract async *p: void; } +class StaticAbstractAsyncGeneratorProperty { abstract static async *p: void; } diff --git a/src/parser/test/flow/abstract_class/generator.tree.json b/src/parser/test/flow/abstract_class/generator.tree.json new file mode 100644 index 00000000000..400067fcf6f --- /dev/null +++ b/src/parser/test/flow/abstract_class/generator.tree.json @@ -0,0 +1,238 @@ +{ + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":5,"column":78}}, + "range":[0,304], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":72}}, + "range":[0,72], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":28}}, + "range":[6,28], + "name":"AbstractAsyncGenerator", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":35},"end":{"line":1,"column":72}}, + "range":[35,72], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":37},"end":{"line":1,"column":70}}, + "range":[37,70], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":60},"end":{"line":1,"column":61}}, + "range":[60,61], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":61},"end":{"line":1,"column":70}}, + "range":[61,70], + "params":[], + "async":true, + "generator":true, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":65},"end":{"line":1,"column":69}}, + "range":[65,69] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":72}}, + "range":[73,145], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":6},"end":{"line":2,"column":34}}, + "range":[79,107], + "name":"StaticAbstractAsyncGenerator", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":2,"column":35},"end":{"line":2,"column":72}}, + "range":[108,145], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":2,"column":37},"end":{"line":2,"column":70}}, + "range":[110,143], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":60},"end":{"line":2,"column":61}}, + "range":[133,134], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":61},"end":{"line":2,"column":70}}, + "range":[134,143], + "params":[], + "async":true, + "generator":true, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":65},"end":{"line":2,"column":69}}, + "range":[138,142] + }, + "rest":null, + "typeParameters":null + }, + "static":true + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":78}}, + "range":[147,225], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":6},"end":{"line":4,"column":36}}, + "range":[153,183], + "name":"AbstractAsyncGeneratorProperty", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":4,"column":43},"end":{"line":4,"column":78}}, + "range":[190,225], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":4,"column":45},"end":{"line":4,"column":76}}, + "range":[192,223], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":68},"end":{"line":4,"column":69}}, + "range":[215,216], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":69},"end":{"line":4,"column":75}}, + "range":[216,222], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":71},"end":{"line":4,"column":75}}, + "range":[218,222] + } + }, + "computed":false, + "static":false, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":5,"column":0},"end":{"line":5,"column":78}}, + "range":[226,304], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":5,"column":6},"end":{"line":5,"column":42}}, + "range":[232,268], + "name":"StaticAbstractAsyncGeneratorProperty", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":5,"column":43},"end":{"line":5,"column":78}}, + "range":[269,304], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":5,"column":45},"end":{"line":5,"column":76}}, + "range":[271,302], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":5,"column":68},"end":{"line":5,"column":69}}, + "range":[294,295], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":5,"column":69},"end":{"line":5,"column":75}}, + "range":[295,301], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":5,"column":71},"end":{"line":5,"column":75}}, + "range":[297,301] + } + }, + "computed":false, + "static":true, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + } + ], + "comments":[], + "errors":[ + { + "loc":{"source":null,"start":{"line":4,"column":69},"end":{"line":4,"column":70}}, + "message":"Unexpected token :" + }, + { + "loc":{"source":null,"start":{"line":4,"column":45},"end":{"line":4,"column":76}}, + "message":"Abstract properties are not allowed." + }, + { + "loc":{"source":null,"start":{"line":5,"column":69},"end":{"line":5,"column":70}}, + "message":"Unexpected token :" + }, + { + "loc":{"source":null,"start":{"line":5,"column":45},"end":{"line":5,"column":76}}, + "message":"Abstract properties are not allowed." + } + ] +} diff --git a/src/parser/test/flow/abstract_class/get.js b/src/parser/test/flow/abstract_class/get.js new file mode 100644 index 00000000000..4cc6620dcef --- /dev/null +++ b/src/parser/test/flow/abstract_class/get.js @@ -0,0 +1,14 @@ +class AbstractGetMethod { abstract get(): void; } +class AbstractStaticGetMethod { abstract static get(): void; } +declare class AbstractGetMethodDecl { abstract get(): void; } +declare class AbstractStaticGetMethodDecl { abstract static get(): void; } + +class AbstractGetter { abstract get p(): void {} } //Error +class AbstractStaticGetter { abstract static get p(): void {} } //Error +declare class AbstractGetterDecl { abstract get p(): void; } //Error +declare class AbstractStaticGetterDecl { abstract static get p(): void; } //Error + +class GetterNamedAbstract { get abstract(): void {} } +class StaticGetterNamedAbstract { static get abstract(): void {} } +declare class GetterNamedAbstractDecl { get abstract(): void; } +declare class StaticGetterNamedAbstractDecl { static get abstract(): void; } diff --git a/src/parser/test/flow/abstract_class/get.options.json b/src/parser/test/flow/abstract_class/get.options.json new file mode 100644 index 00000000000..ca050bc545d --- /dev/null +++ b/src/parser/test/flow/abstract_class/get.options.json @@ -0,0 +1,4 @@ +{ + "esproposal_class_static_fields": true, + "esproposal_class_instance_fields": true +} diff --git a/src/parser/test/flow/abstract_class/get.tree.json b/src/parser/test/flow/abstract_class/get.tree.json new file mode 100644 index 00000000000..edd6c8989e6 --- /dev/null +++ b/src/parser/test/flow/abstract_class/get.tree.json @@ -0,0 +1,793 @@ +{ + "errors":[ + { + "loc":{"source":null,"start":{"line":6,"column":41},"end":{"line":6,"column":73}}, + "message":"Abstract getters are not allowed." + }, + { + "loc":{"source":null,"start":{"line":7,"column":41},"end":{"line":7,"column":73}}, + "message":"Abstract getters are not allowed." + }, + { + "loc":{"source":null,"start":{"line":8,"column":41},"end":{"line":8,"column":70}}, + "message":"Abstract getters are not allowed." + }, + { + "loc":{"source":null,"start":{"line":9,"column":41},"end":{"line":9,"column":70}}, + "message":"Abstract getters are not allowed." + } + ], + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":14,"column":78}}, + "range":[0,953], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":74}}, + "range":[0,74], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":31}}, + "range":[14,31], + "name":"AbstractGetMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":42},"end":{"line":1,"column":74}}, + "range":[42,74], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":44},"end":{"line":1,"column":72}}, + "range":[44,72], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":60},"end":{"line":1,"column":63}}, + "range":[60,63], + "name":"get", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":63},"end":{"line":1,"column":72}}, + "range":[63,72], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":67},"end":{"line":1,"column":71}}, + "range":[67,71] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":74}}, + "range":[75,149], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":14},"end":{"line":2,"column":37}}, + "range":[89,112], + "name":"AbstractStaticGetMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":2,"column":42},"end":{"line":2,"column":74}}, + "range":[117,149], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":2,"column":44},"end":{"line":2,"column":72}}, + "range":[119,147], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":60},"end":{"line":2,"column":63}}, + "range":[135,138], + "name":"get", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":63},"end":{"line":2,"column":72}}, + "range":[138,147], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":67},"end":{"line":2,"column":71}}, + "range":[142,146] + }, + "rest":null, + "typeParameters":null + }, + "static":true + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":74}}, + "range":[150,224], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":14},"end":{"line":3,"column":35}}, + "range":[164,185], + "name":"AbstractGetMethodDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":42},"end":{"line":3,"column":74}}, + "range":[192,224], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":3,"column":44},"end":{"line":3,"column":71}}, + "range":[194,221], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":60},"end":{"line":3,"column":63}}, + "range":[210,213], + "name":"get", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":44},"end":{"line":3,"column":71}}, + "range":[194,221], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":67},"end":{"line":3,"column":71}}, + "range":[217,221] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":74}}, + "range":[225,299], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":14},"end":{"line":4,"column":41}}, + "range":[239,266], + "name":"AbstractStaticGetMethodDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":42},"end":{"line":4,"column":74}}, + "range":[267,299], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":4,"column":44},"end":{"line":4,"column":71}}, + "range":[269,296], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":60},"end":{"line":4,"column":63}}, + "range":[285,288], + "name":"get", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":44},"end":{"line":4,"column":71}}, + "range":[269,296], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":67},"end":{"line":4,"column":71}}, + "range":[292,296] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":true, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":6,"column":0},"end":{"line":6,"column":75}}, + "range":[301,376], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":14},"end":{"line":6,"column":28}}, + "range":[315,329], + "name":"AbstractGetter", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":6,"column":39},"end":{"line":6,"column":75}}, + "range":[340,376], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":6,"column":41},"end":{"line":6,"column":73}}, + "range":[342,374], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":61},"end":{"line":6,"column":62}}, + "range":[362,363], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":6,"column":62},"end":{"line":6,"column":73}}, + "range":[363,374], + "id":null, + "params":[], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":6,"column":71},"end":{"line":6,"column":73}}, + "range":[372,374], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":64},"end":{"line":6,"column":70}}, + "range":[365,371], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":66},"end":{"line":6,"column":70}}, + "range":[367,371] + } + }, + "typeParameters":null + }, + "kind":"get", + "static":false, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":7,"column":0},"end":{"line":7,"column":75}}, + "range":[385,460], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":14},"end":{"line":7,"column":34}}, + "range":[399,419], + "name":"AbstractStaticGetter", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":7,"column":39},"end":{"line":7,"column":75}}, + "range":[424,460], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":7,"column":41},"end":{"line":7,"column":73}}, + "range":[426,458], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":61},"end":{"line":7,"column":62}}, + "range":[446,447], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":7,"column":62},"end":{"line":7,"column":73}}, + "range":[447,458], + "id":null, + "params":[], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":7,"column":71},"end":{"line":7,"column":73}}, + "range":[456,458], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":64},"end":{"line":7,"column":70}}, + "range":[449,455], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":66},"end":{"line":7,"column":70}}, + "range":[451,455] + } + }, + "typeParameters":null + }, + "kind":"get", + "static":true, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":8,"column":0},"end":{"line":8,"column":75}}, + "range":[469,544], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":14},"end":{"line":8,"column":32}}, + "range":[483,501], + "name":"AbstractGetterDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":39},"end":{"line":8,"column":75}}, + "range":[508,544], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":8,"column":41},"end":{"line":8,"column":70}}, + "range":[510,539], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":61},"end":{"line":8,"column":62}}, + "range":[530,531], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":41},"end":{"line":8,"column":70}}, + "range":[510,539], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":66},"end":{"line":8,"column":70}}, + "range":[535,539] + }, + "rest":null, + "typeParameters":null + }, + "method":false, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"get" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":9,"column":0},"end":{"line":9,"column":75}}, + "range":[553,628], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":14},"end":{"line":9,"column":38}}, + "range":[567,591], + "name":"AbstractStaticGetterDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":39},"end":{"line":9,"column":75}}, + "range":[592,628], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":9,"column":41},"end":{"line":9,"column":70}}, + "range":[594,623], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":61},"end":{"line":9,"column":62}}, + "range":[614,615], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":41},"end":{"line":9,"column":70}}, + "range":[594,623], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":66},"end":{"line":9,"column":70}}, + "range":[619,623] + }, + "rest":null, + "typeParameters":null + }, + "method":false, + "optional":false, + "abstract":false, + "static":true, + "variance":null, + "kind":"get" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":11,"column":0},"end":{"line":11,"column":78}}, + "range":[638,716], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":11,"column":14},"end":{"line":11,"column":33}}, + "range":[652,671], + "name":"GetterNamedAbstract", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":11,"column":44},"end":{"line":11,"column":78}}, + "range":[682,716], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":11,"column":53},"end":{"line":11,"column":76}}, + "range":[691,714], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":11,"column":57},"end":{"line":11,"column":65}}, + "range":[695,703], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":11,"column":65},"end":{"line":11,"column":76}}, + "range":[703,714], + "id":null, + "params":[], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":11,"column":74},"end":{"line":11,"column":76}}, + "range":[712,714], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":11,"column":67},"end":{"line":11,"column":73}}, + "range":[705,711], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":11,"column":69},"end":{"line":11,"column":73}}, + "range":[707,711] + } + }, + "typeParameters":null + }, + "kind":"get", + "static":false, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":12,"column":0},"end":{"line":12,"column":78}}, + "range":[717,795], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":12,"column":14},"end":{"line":12,"column":39}}, + "range":[731,756], + "name":"StaticGetterNamedAbstract", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":12,"column":44},"end":{"line":12,"column":78}}, + "range":[761,795], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":12,"column":46},"end":{"line":12,"column":76}}, + "range":[763,793], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":12,"column":57},"end":{"line":12,"column":65}}, + "range":[774,782], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":12,"column":65},"end":{"line":12,"column":76}}, + "range":[782,793], + "id":null, + "params":[], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":12,"column":74},"end":{"line":12,"column":76}}, + "range":[791,793], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":12,"column":67},"end":{"line":12,"column":73}}, + "range":[784,790], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":12,"column":69},"end":{"line":12,"column":73}}, + "range":[786,790] + } + }, + "typeParameters":null + }, + "kind":"get", + "static":true, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":13,"column":0},"end":{"line":13,"column":78}}, + "range":[796,874], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":13,"column":14},"end":{"line":13,"column":37}}, + "range":[810,833], + "name":"GetterNamedAbstractDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":13,"column":44},"end":{"line":13,"column":78}}, + "range":[840,874], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":13,"column":53},"end":{"line":13,"column":73}}, + "range":[849,869], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":13,"column":57},"end":{"line":13,"column":65}}, + "range":[853,861], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":13,"column":53},"end":{"line":13,"column":73}}, + "range":[849,869], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":13,"column":69},"end":{"line":13,"column":73}}, + "range":[865,869] + }, + "rest":null, + "typeParameters":null + }, + "method":false, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"get" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":14,"column":0},"end":{"line":14,"column":78}}, + "range":[875,953], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":14,"column":14},"end":{"line":14,"column":43}}, + "range":[889,918], + "name":"StaticGetterNamedAbstractDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":14,"column":44},"end":{"line":14,"column":78}}, + "range":[919,953], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":14,"column":46},"end":{"line":14,"column":73}}, + "range":[921,948], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":14,"column":57},"end":{"line":14,"column":65}}, + "range":[932,940], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":14,"column":46},"end":{"line":14,"column":73}}, + "range":[921,948], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":14,"column":69},"end":{"line":14,"column":73}}, + "range":[944,948] + }, + "rest":null, + "typeParameters":null + }, + "method":false, + "optional":false, + "abstract":false, + "static":true, + "variance":null, + "kind":"get" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + } + ], + "comments":[ + { + "type":"Line", + "loc":{"source":null,"start":{"line":6,"column":76},"end":{"line":6,"column":83}}, + "range":[377,384], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":7,"column":76},"end":{"line":7,"column":83}}, + "range":[461,468], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":8,"column":76},"end":{"line":8,"column":83}}, + "range":[545,552], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":9,"column":76},"end":{"line":9,"column":83}}, + "range":[629,636], + "value":"Error" + } + ] +} diff --git a/src/parser/test/flow/abstract_class/identifier.js b/src/parser/test/flow/abstract_class/identifier.js new file mode 100644 index 00000000000..0dd5558ff64 --- /dev/null +++ b/src/parser/test/flow/abstract_class/identifier.js @@ -0,0 +1,9 @@ +class MethodNamedAbstract { abstract(): void {} } +class StaticMethodNamedAbstract { static abstract(): void {} } +declare class MethodNamedAbstractDecl { abstract(): void; } +declare class StaticMethodNamedAbstractDecl { static abstract(): void; } + +class PropertyNamedAbstract { abstract: void; } +class StaticPropertyNamedAbstract { static abstract: void; } +declare class PropertyNamedAbstractDecl { abstract: void; } +declare class StaticPropertyNamedAbstractDecl { static abstract: void; } diff --git a/src/parser/test/flow/abstract_class/identifier.tree.json b/src/parser/test/flow/abstract_class/identifier.tree.json new file mode 100644 index 00000000000..43f63f45936 --- /dev/null +++ b/src/parser/test/flow/abstract_class/identifier.tree.json @@ -0,0 +1,468 @@ +{ + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":9,"column":72}}, + "range":[0,592], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":74}}, + "range":[0,74], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":33}}, + "range":[14,33], + "name":"MethodNamedAbstract", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":44},"end":{"line":1,"column":74}}, + "range":[44,74], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":53},"end":{"line":1,"column":72}}, + "range":[53,72], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":53},"end":{"line":1,"column":61}}, + "range":[53,61], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":1,"column":61},"end":{"line":1,"column":72}}, + "range":[61,72], + "id":null, + "params":[], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":1,"column":70},"end":{"line":1,"column":72}}, + "range":[70,72], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":63},"end":{"line":1,"column":69}}, + "range":[63,69], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":65},"end":{"line":1,"column":69}}, + "range":[65,69] + } + }, + "typeParameters":null + }, + "kind":"method", + "static":false, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":74}}, + "range":[75,149], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":14},"end":{"line":2,"column":39}}, + "range":[89,114], + "name":"StaticMethodNamedAbstract", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":2,"column":44},"end":{"line":2,"column":74}}, + "range":[119,149], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":2,"column":46},"end":{"line":2,"column":72}}, + "range":[121,147], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":53},"end":{"line":2,"column":61}}, + "range":[128,136], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":2,"column":61},"end":{"line":2,"column":72}}, + "range":[136,147], + "id":null, + "params":[], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":2,"column":70},"end":{"line":2,"column":72}}, + "range":[145,147], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":63},"end":{"line":2,"column":69}}, + "range":[138,144], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":65},"end":{"line":2,"column":69}}, + "range":[140,144] + } + }, + "typeParameters":null + }, + "kind":"method", + "static":true, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":74}}, + "range":[150,224], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":14},"end":{"line":3,"column":37}}, + "range":[164,187], + "name":"MethodNamedAbstractDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":44},"end":{"line":3,"column":74}}, + "range":[194,224], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":3,"column":53},"end":{"line":3,"column":69}}, + "range":[203,219], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":53},"end":{"line":3,"column":61}}, + "range":[203,211], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":53},"end":{"line":3,"column":69}}, + "range":[203,219], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":65},"end":{"line":3,"column":69}}, + "range":[215,219] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":74}}, + "range":[225,299], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":14},"end":{"line":4,"column":43}}, + "range":[239,268], + "name":"StaticMethodNamedAbstractDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":44},"end":{"line":4,"column":74}}, + "range":[269,299], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":4,"column":46},"end":{"line":4,"column":69}}, + "range":[271,294], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":53},"end":{"line":4,"column":61}}, + "range":[278,286], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":46},"end":{"line":4,"column":69}}, + "range":[271,294], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":65},"end":{"line":4,"column":69}}, + "range":[290,294] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":false, + "static":true, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":6,"column":0},"end":{"line":6,"column":72}}, + "range":[301,373], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":14},"end":{"line":6,"column":35}}, + "range":[315,336], + "name":"PropertyNamedAbstract", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":6,"column":46},"end":{"line":6,"column":72}}, + "range":[347,373], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":6,"column":55},"end":{"line":6,"column":70}}, + "range":[356,371], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":55},"end":{"line":6,"column":63}}, + "range":[356,364], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":63},"end":{"line":6,"column":69}}, + "range":[364,370], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":65},"end":{"line":6,"column":69}}, + "range":[366,370] + } + }, + "computed":false, + "static":false, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":7,"column":0},"end":{"line":7,"column":72}}, + "range":[374,446], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":14},"end":{"line":7,"column":41}}, + "range":[388,415], + "name":"StaticPropertyNamedAbstract", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":7,"column":46},"end":{"line":7,"column":72}}, + "range":[420,446], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":7,"column":48},"end":{"line":7,"column":70}}, + "range":[422,444], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":55},"end":{"line":7,"column":63}}, + "range":[429,437], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":63},"end":{"line":7,"column":69}}, + "range":[437,443], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":65},"end":{"line":7,"column":69}}, + "range":[439,443] + } + }, + "computed":false, + "static":true, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":8,"column":0},"end":{"line":8,"column":72}}, + "range":[447,519], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":14},"end":{"line":8,"column":39}}, + "range":[461,486], + "name":"PropertyNamedAbstractDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":46},"end":{"line":8,"column":72}}, + "range":[493,519], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":8,"column":55},"end":{"line":8,"column":69}}, + "range":[502,516], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":55},"end":{"line":8,"column":63}}, + "range":[502,510], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":65},"end":{"line":8,"column":69}}, + "range":[512,516] + }, + "method":false, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":9,"column":0},"end":{"line":9,"column":72}}, + "range":[520,592], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":14},"end":{"line":9,"column":45}}, + "range":[534,565], + "name":"StaticPropertyNamedAbstractDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":46},"end":{"line":9,"column":72}}, + "range":[566,592], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":9,"column":48},"end":{"line":9,"column":69}}, + "range":[568,589], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":55},"end":{"line":9,"column":63}}, + "range":[575,583], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":65},"end":{"line":9,"column":69}}, + "range":[585,589] + }, + "method":false, + "optional":false, + "abstract":false, + "static":true, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + } + ], + "comments":[] +} diff --git a/src/parser/test/flow/abstract_class/immediate.js b/src/parser/test/flow/abstract_class/immediate.js new file mode 100644 index 00000000000..c7f35627a89 --- /dev/null +++ b/src/parser/test/flow/abstract_class/immediate.js @@ -0,0 +1,9 @@ +class LeadingMethod { m(): void {} abstract m(): void; } // Error +declare class LeadingMethodDecl { m(): void; abstract m(): void; } // Error +class LeadingProperty { m: void; abstract m(): void; } // Error +declare class LeadingPropertyDecl { m: void; abstract m(): void; } // Error + +class TrailingMethod { abstract m(): void; m(): void {} } // Error +declare class TrailingMethodDecl { abstract m(): void; m(): void; } // Error +class TrailingProperty { abstract m(): void; m: void; } // Error +declare class TrailingPropertyDecl { abstract m(): void; m: void; } // Error diff --git a/src/parser/test/flow/abstract_class/immediate.tree.json b/src/parser/test/flow/abstract_class/immediate.tree.json new file mode 100644 index 00000000000..4770786acd6 --- /dev/null +++ b/src/parser/test/flow/abstract_class/immediate.tree.json @@ -0,0 +1,803 @@ +{ + "errors":[ + { + "loc":{"source":null,"start":{"line":1,"column":49},"end":{"line":1,"column":68}}, + "message":"Abstract method `m` is implemented locally." + }, + { + "loc":{"source":null,"start":{"line":2,"column":49},"end":{"line":2,"column":67}}, + "message":"Abstract method `m` is implemented locally." + }, + { + "loc":{"source":null,"start":{"line":3,"column":49},"end":{"line":3,"column":68}}, + "message":"Abstract method `m` is implemented locally." + }, + { + "loc":{"source":null,"start":{"line":4,"column":49},"end":{"line":4,"column":67}}, + "message":"Abstract method `m` is implemented locally." + }, + { + "loc":{"source":null,"start":{"line":6,"column":37},"end":{"line":6,"column":56}}, + "message":"Abstract method `m` is implemented locally." + }, + { + "loc":{"source":null,"start":{"line":7,"column":37},"end":{"line":7,"column":55}}, + "message":"Abstract method `m` is implemented locally." + }, + { + "loc":{"source":null,"start":{"line":8,"column":37},"end":{"line":8,"column":56}}, + "message":"Abstract method `m` is implemented locally." + }, + { + "loc":{"source":null,"start":{"line":9,"column":37},"end":{"line":9,"column":55}}, + "message":"Abstract method `m` is implemented locally." + } + ], + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":9,"column":71}}, + "range":[0,635], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":70}}, + "range":[0,70], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":27}}, + "range":[14,27], + "name":"LeadingMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":34},"end":{"line":1,"column":70}}, + "range":[34,70], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":36},"end":{"line":1,"column":48}}, + "range":[36,48], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":36},"end":{"line":1,"column":37}}, + "range":[36,37], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":1,"column":37},"end":{"line":1,"column":48}}, + "range":[37,48], + "id":null, + "params":[], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":1,"column":46},"end":{"line":1,"column":48}}, + "range":[46,48], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":39},"end":{"line":1,"column":45}}, + "range":[39,45], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":41},"end":{"line":1,"column":45}}, + "range":[41,45] + } + }, + "typeParameters":null + }, + "kind":"method", + "static":false, + "computed":false, + "decorators":[] + }, + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":49},"end":{"line":1,"column":68}}, + "range":[49,68], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":58},"end":{"line":1,"column":59}}, + "range":[58,59], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":59},"end":{"line":1,"column":68}}, + "range":[59,68], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":63},"end":{"line":1,"column":67}}, + "range":[63,67] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":70}}, + "range":[80,150], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":14},"end":{"line":2,"column":31}}, + "range":[94,111], + "name":"LeadingMethodDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":34},"end":{"line":2,"column":70}}, + "range":[114,150], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":2,"column":36},"end":{"line":2,"column":45}}, + "range":[116,125], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":36},"end":{"line":2,"column":37}}, + "range":[116,117], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":36},"end":{"line":2,"column":45}}, + "range":[116,125], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":41},"end":{"line":2,"column":45}}, + "range":[121,125] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"init" + }, + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":2,"column":49},"end":{"line":2,"column":67}}, + "range":[129,147], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":58},"end":{"line":2,"column":59}}, + "range":[138,139], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":49},"end":{"line":2,"column":67}}, + "range":[129,147], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":63},"end":{"line":2,"column":67}}, + "range":[143,147] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":70}}, + "range":[160,230], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":14},"end":{"line":3,"column":29}}, + "range":[174,189], + "name":"LeadingProperty", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":3,"column":34},"end":{"line":3,"column":70}}, + "range":[194,230], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":3,"column":36},"end":{"line":3,"column":46}}, + "range":[196,206], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":36},"end":{"line":3,"column":37}}, + "range":[196,197], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":37},"end":{"line":3,"column":45}}, + "range":[197,205], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":41},"end":{"line":3,"column":45}}, + "range":[201,205] + } + }, + "computed":false, + "static":false, + "variance":null + }, + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":3,"column":49},"end":{"line":3,"column":68}}, + "range":[209,228], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":58},"end":{"line":3,"column":59}}, + "range":[218,219], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":59},"end":{"line":3,"column":68}}, + "range":[219,228], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":63},"end":{"line":3,"column":67}}, + "range":[223,227] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":70}}, + "range":[240,310], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":14},"end":{"line":4,"column":33}}, + "range":[254,273], + "name":"LeadingPropertyDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":34},"end":{"line":4,"column":70}}, + "range":[274,310], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":4,"column":36},"end":{"line":4,"column":45}}, + "range":[276,285], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":36},"end":{"line":4,"column":37}}, + "range":[276,277], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":41},"end":{"line":4,"column":45}}, + "range":[281,285] + }, + "method":false, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"init" + }, + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":4,"column":49},"end":{"line":4,"column":67}}, + "range":[289,307], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":58},"end":{"line":4,"column":59}}, + "range":[298,299], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":49},"end":{"line":4,"column":67}}, + "range":[289,307], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":63},"end":{"line":4,"column":67}}, + "range":[303,307] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":6,"column":0},"end":{"line":6,"column":71}}, + "range":[321,392], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":14},"end":{"line":6,"column":28}}, + "range":[335,349], + "name":"TrailingMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":6,"column":35},"end":{"line":6,"column":71}}, + "range":[356,392], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":6,"column":37},"end":{"line":6,"column":56}}, + "range":[358,377], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":46},"end":{"line":6,"column":47}}, + "range":[367,368], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":47},"end":{"line":6,"column":56}}, + "range":[368,377], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":51},"end":{"line":6,"column":55}}, + "range":[372,376] + }, + "rest":null, + "typeParameters":null + }, + "static":false + }, + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":6,"column":57},"end":{"line":6,"column":69}}, + "range":[378,390], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":57},"end":{"line":6,"column":58}}, + "range":[378,379], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":6,"column":58},"end":{"line":6,"column":69}}, + "range":[379,390], + "id":null, + "params":[], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":6,"column":67},"end":{"line":6,"column":69}}, + "range":[388,390], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":60},"end":{"line":6,"column":66}}, + "range":[381,387], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":62},"end":{"line":6,"column":66}}, + "range":[383,387] + } + }, + "typeParameters":null + }, + "kind":"method", + "static":false, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":7,"column":0},"end":{"line":7,"column":71}}, + "range":[402,473], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":14},"end":{"line":7,"column":32}}, + "range":[416,434], + "name":"TrailingMethodDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":35},"end":{"line":7,"column":71}}, + "range":[437,473], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":7,"column":37},"end":{"line":7,"column":55}}, + "range":[439,457], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":46},"end":{"line":7,"column":47}}, + "range":[448,449], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":37},"end":{"line":7,"column":55}}, + "range":[439,457], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":51},"end":{"line":7,"column":55}}, + "range":[453,457] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":false, + "variance":null, + "kind":"init" + }, + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":7,"column":57},"end":{"line":7,"column":66}}, + "range":[459,468], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":57},"end":{"line":7,"column":58}}, + "range":[459,460], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":57},"end":{"line":7,"column":66}}, + "range":[459,468], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":62},"end":{"line":7,"column":66}}, + "range":[464,468] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":8,"column":0},"end":{"line":8,"column":71}}, + "range":[483,554], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":14},"end":{"line":8,"column":30}}, + "range":[497,513], + "name":"TrailingProperty", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":8,"column":35},"end":{"line":8,"column":71}}, + "range":[518,554], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":8,"column":37},"end":{"line":8,"column":56}}, + "range":[520,539], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":46},"end":{"line":8,"column":47}}, + "range":[529,530], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":47},"end":{"line":8,"column":56}}, + "range":[530,539], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":51},"end":{"line":8,"column":55}}, + "range":[534,538] + }, + "rest":null, + "typeParameters":null + }, + "static":false + }, + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":8,"column":57},"end":{"line":8,"column":67}}, + "range":[540,550], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":57},"end":{"line":8,"column":58}}, + "range":[540,541], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":58},"end":{"line":8,"column":66}}, + "range":[541,549], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":62},"end":{"line":8,"column":66}}, + "range":[545,549] + } + }, + "computed":false, + "static":false, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":9,"column":0},"end":{"line":9,"column":71}}, + "range":[564,635], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":14},"end":{"line":9,"column":34}}, + "range":[578,598], + "name":"TrailingPropertyDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":35},"end":{"line":9,"column":71}}, + "range":[599,635], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":9,"column":37},"end":{"line":9,"column":55}}, + "range":[601,619], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":46},"end":{"line":9,"column":47}}, + "range":[610,611], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":37},"end":{"line":9,"column":55}}, + "range":[601,619], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":51},"end":{"line":9,"column":55}}, + "range":[615,619] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":false, + "variance":null, + "kind":"init" + }, + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":9,"column":57},"end":{"line":9,"column":66}}, + "range":[621,630], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":57},"end":{"line":9,"column":58}}, + "range":[621,622], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":62},"end":{"line":9,"column":66}}, + "range":[626,630] + }, + "method":false, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + } + ], + "comments":[ + { + "type":"Line", + "loc":{"source":null,"start":{"line":1,"column":71},"end":{"line":1,"column":79}}, + "range":[71,79], + "value":" Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":2,"column":71},"end":{"line":2,"column":79}}, + "range":[151,159], + "value":" Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":3,"column":71},"end":{"line":3,"column":79}}, + "range":[231,239], + "value":" Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":4,"column":71},"end":{"line":4,"column":79}}, + "range":[311,319], + "value":" Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":6,"column":72},"end":{"line":6,"column":80}}, + "range":[393,401], + "value":" Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":7,"column":72},"end":{"line":7,"column":80}}, + "range":[474,482], + "value":" Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":8,"column":72},"end":{"line":8,"column":80}}, + "range":[555,563], + "value":" Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":9,"column":72},"end":{"line":9,"column":80}}, + "range":[636,644], + "value":" Error" + } + ] +} diff --git a/src/parser/test/flow/abstract_class/indexer.js b/src/parser/test/flow/abstract_class/indexer.js new file mode 100644 index 00000000000..9c49f4d605f --- /dev/null +++ b/src/parser/test/flow/abstract_class/indexer.js @@ -0,0 +1,4 @@ +class AbstractIndexer { abstract [string]: void; } //Error, error_unexpected on `[`, abstract properties not allowed is ok too +class StaticAbstractIndexer { abstract static [string]: void; } //Error +declare class AbstractIndexerDecl { abstract [string]: void; } //Error +declare class StaticAbstractIndexerDecl { abstract static [string]: void; } //Error diff --git a/src/parser/test/flow/abstract_class/indexer.tree.json b/src/parser/test/flow/abstract_class/indexer.tree.json new file mode 100644 index 00000000000..0b8c79653ff --- /dev/null +++ b/src/parser/test/flow/abstract_class/indexer.tree.json @@ -0,0 +1,249 @@ +{ + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":4,"column":75}}, + "range":[0,395], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":75}}, + "range":[0,75], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":21}}, + "range":[6,21], + "name":"AbstractIndexer", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":40},"end":{"line":1,"column":75}}, + "range":[40,75], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":1,"column":42},"end":{"line":1,"column":73}}, + "range":[42,73], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":59},"end":{"line":1,"column":65}}, + "range":[59,65], + "name":"string", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":66},"end":{"line":1,"column":72}}, + "range":[66,72], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":68},"end":{"line":1,"column":72}}, + "range":[68,72] + } + }, + "computed":true, + "static":false, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":75}}, + "range":[152,227], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":6},"end":{"line":2,"column":27}}, + "range":[158,179], + "name":"StaticAbstractIndexer", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":2,"column":40},"end":{"line":2,"column":75}}, + "range":[192,227], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":2,"column":42},"end":{"line":2,"column":73}}, + "range":[194,225], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":59},"end":{"line":2,"column":65}}, + "range":[211,217], + "name":"string", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":66},"end":{"line":2,"column":72}}, + "range":[218,224], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":68},"end":{"line":2,"column":72}}, + "range":[220,224] + } + }, + "computed":true, + "static":true, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":75}}, + "range":[236,311], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":14},"end":{"line":3,"column":33}}, + "range":[250,269], + "name":"AbstractIndexerDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":40},"end":{"line":3,"column":75}}, + "range":[276,311], + "exact":false, + "properties":[], + "indexers":[ + { + "type":"ObjectTypeIndexer", + "loc":{"source":null,"start":{"line":3,"column":42},"end":{"line":3,"column":72}}, + "range":[278,308], + "id":null, + "key":{ + "type":"StringTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":59},"end":{"line":3,"column":65}}, + "range":[295,301] + }, + "value":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":68},"end":{"line":3,"column":72}}, + "range":[304,308] + }, + "static":false, + "variance":null + } + ], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":75}}, + "range":[320,395], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":14},"end":{"line":4,"column":39}}, + "range":[334,359], + "name":"StaticAbstractIndexerDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":40},"end":{"line":4,"column":75}}, + "range":[360,395], + "exact":false, + "properties":[], + "indexers":[ + { + "type":"ObjectTypeIndexer", + "loc":{"source":null,"start":{"line":4,"column":42},"end":{"line":4,"column":72}}, + "range":[362,392], + "id":null, + "key":{ + "type":"StringTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":59},"end":{"line":4,"column":65}}, + "range":[379,385] + }, + "value":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":68},"end":{"line":4,"column":72}}, + "range":[388,392] + }, + "static":true, + "variance":null + } + ], + "callProperties":[] + }, + "extends":[] + } + ], + "comments":[ + { + "type":"Line", + "loc":{"source":null,"start":{"line":1,"column":76},"end":{"line":1,"column":151}}, + "range":[76,151], + "value":"Error, error_unexpected on `[`, abstract properties not allowed is ok too" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":2,"column":76},"end":{"line":2,"column":83}}, + "range":[228,235], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":3,"column":76},"end":{"line":3,"column":83}}, + "range":[312,319], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":4,"column":76},"end":{"line":4,"column":83}}, + "range":[396,403], + "value":"Error" + } + ], + "errors":[ + { + "loc":{"source":null,"start":{"line":1,"column":58},"end":{"line":1,"column":59}}, + "message":"Expected an identifier." + }, + { + "loc":{"source":null,"start":{"line":1,"column":42},"end":{"line":1,"column":73}}, + "message":"Abstract properties are not allowed." + }, + { + "loc":{"source":null,"start":{"line":2,"column":58},"end":{"line":2,"column":59}}, + "message":"Expected an identifier." + }, + { + "loc":{"source":null,"start":{"line":2,"column":42},"end":{"line":2,"column":73}}, + "message":"Abstract properties are not allowed." + }, + { + "loc":{"source":null,"start":{"line":3,"column":42},"end":{"line":3,"column":72}}, + "message":"Abstract indexers are not allowed." + }, + { + "loc":{"source":null,"start":{"line":4,"column":42},"end":{"line":4,"column":72}}, + "message":"Abstract indexers are not allowed." + } + ] +} diff --git a/src/parser/test/flow/abstract_class/object.js b/src/parser/test/flow/abstract_class/object.js new file mode 100644 index 00000000000..51eb6431d40 --- /dev/null +++ b/src/parser/test/flow/abstract_class/object.js @@ -0,0 +1,26 @@ +let abstractNamedMethod = { + abstract(): void {} +}; +type AbstractNamedMethodT = { + abstract(): void +}; +let abstractNamedGetter = { + get abstract(): void {} +}; +type AbstractNamedGetterT = { + get abstract(): void +}; +let abstractNamedSetter = { + set abstract(p: void): void {} +}; +type AbstractNamedSetter = { + set abstract(p: void): void +}; +let abstractNamedProperty = { + abstract: 1 +}; +type AbstractNamedPropertyT = { + abstract: number +}; + + diff --git a/src/parser/test/flow/abstract_class/object.options.json b/src/parser/test/flow/abstract_class/object.options.json new file mode 100644 index 00000000000..ca050bc545d --- /dev/null +++ b/src/parser/test/flow/abstract_class/object.options.json @@ -0,0 +1,4 @@ +{ + "esproposal_class_static_fields": true, + "esproposal_class_instance_fields": true +} diff --git a/src/parser/test/flow/abstract_class/object.tree.json b/src/parser/test/flow/abstract_class/object.tree.json new file mode 100644 index 00000000000..c1cd06d86ff --- /dev/null +++ b/src/parser/test/flow/abstract_class/object.tree.json @@ -0,0 +1,539 @@ +{ + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":24,"column":2}}, + "range":[0,444], + "body":[ + { + "type":"VariableDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":3,"column":2}}, + "range":[0,52], + "declarations":[ + { + "type":"VariableDeclarator", + "loc":{"source":null,"start":{"line":1,"column":4},"end":{"line":3,"column":1}}, + "range":[4,51], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":4},"end":{"line":1,"column":23}}, + "range":[4,23], + "name":"abstractNamedMethod", + "typeAnnotation":null, + "optional":false + }, + "init":{ + "type":"ObjectExpression", + "loc":{"source":null,"start":{"line":1,"column":26},"end":{"line":3,"column":1}}, + "range":[26,51], + "properties":[ + { + "type":"Property", + "loc":{"source":null,"start":{"line":2,"column":2},"end":{"line":2,"column":21}}, + "range":[30,49], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":2},"end":{"line":2,"column":10}}, + "range":[30,38], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":2,"column":10},"end":{"line":2,"column":21}}, + "range":[38,49], + "id":null, + "params":[], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":2,"column":19},"end":{"line":2,"column":21}}, + "range":[47,49], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":12},"end":{"line":2,"column":18}}, + "range":[40,46], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":14},"end":{"line":2,"column":18}}, + "range":[42,46] + } + }, + "typeParameters":null + }, + "kind":"init", + "method":true, + "shorthand":false, + "computed":false + } + ] + } + } + ], + "kind":"let" + }, + { + "type":"TypeAlias", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":6,"column":2}}, + "range":[53,104], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":5},"end":{"line":4,"column":25}}, + "range":[58,78], + "name":"AbstractNamedMethodT", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "right":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":28},"end":{"line":6,"column":1}}, + "range":[81,103], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":5,"column":2},"end":{"line":5,"column":18}}, + "range":[85,101], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":5,"column":2},"end":{"line":5,"column":10}}, + "range":[85,93], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":5,"column":2},"end":{"line":5,"column":18}}, + "range":[85,101], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":5,"column":14},"end":{"line":5,"column":18}}, + "range":[97,101] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + } + }, + { + "type":"VariableDeclaration", + "loc":{"source":null,"start":{"line":7,"column":0},"end":{"line":9,"column":2}}, + "range":[105,161], + "declarations":[ + { + "type":"VariableDeclarator", + "loc":{"source":null,"start":{"line":7,"column":4},"end":{"line":9,"column":1}}, + "range":[109,160], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":4},"end":{"line":7,"column":23}}, + "range":[109,128], + "name":"abstractNamedGetter", + "typeAnnotation":null, + "optional":false + }, + "init":{ + "type":"ObjectExpression", + "loc":{"source":null,"start":{"line":7,"column":26},"end":{"line":9,"column":1}}, + "range":[131,160], + "properties":[ + { + "type":"Property", + "loc":{"source":null,"start":{"line":8,"column":2},"end":{"line":8,"column":25}}, + "range":[135,158], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":6},"end":{"line":8,"column":14}}, + "range":[139,147], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":8,"column":14},"end":{"line":8,"column":25}}, + "range":[147,158], + "id":null, + "params":[], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":8,"column":23},"end":{"line":8,"column":25}}, + "range":[156,158], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":16},"end":{"line":8,"column":22}}, + "range":[149,155], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":18},"end":{"line":8,"column":22}}, + "range":[151,155] + } + }, + "typeParameters":null + }, + "kind":"get", + "method":false, + "shorthand":false, + "computed":false + } + ] + } + } + ], + "kind":"let" + }, + { + "type":"TypeAlias", + "loc":{"source":null,"start":{"line":10,"column":0},"end":{"line":12,"column":2}}, + "range":[162,217], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":10,"column":5},"end":{"line":10,"column":25}}, + "range":[167,187], + "name":"AbstractNamedGetterT", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "right":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":10,"column":28},"end":{"line":12,"column":1}}, + "range":[190,216], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":11,"column":2},"end":{"line":11,"column":22}}, + "range":[194,214], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":11,"column":6},"end":{"line":11,"column":14}}, + "range":[198,206], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":11,"column":2},"end":{"line":11,"column":22}}, + "range":[194,214], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":11,"column":18},"end":{"line":11,"column":22}}, + "range":[210,214] + }, + "rest":null, + "typeParameters":null + }, + "method":false, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"get" + } + ], + "indexers":[], + "callProperties":[] + } + }, + { + "type":"VariableDeclaration", + "loc":{"source":null,"start":{"line":13,"column":0},"end":{"line":15,"column":2}}, + "range":[218,281], + "declarations":[ + { + "type":"VariableDeclarator", + "loc":{"source":null,"start":{"line":13,"column":4},"end":{"line":15,"column":1}}, + "range":[222,280], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":13,"column":4},"end":{"line":13,"column":23}}, + "range":[222,241], + "name":"abstractNamedSetter", + "typeAnnotation":null, + "optional":false + }, + "init":{ + "type":"ObjectExpression", + "loc":{"source":null,"start":{"line":13,"column":26},"end":{"line":15,"column":1}}, + "range":[244,280], + "properties":[ + { + "type":"Property", + "loc":{"source":null,"start":{"line":14,"column":2},"end":{"line":14,"column":32}}, + "range":[248,278], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":14,"column":6},"end":{"line":14,"column":14}}, + "range":[252,260], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":14,"column":14},"end":{"line":14,"column":32}}, + "range":[260,278], + "id":null, + "params":[ + { + "type":"Identifier", + "loc":{"source":null,"start":{"line":14,"column":15},"end":{"line":14,"column":22}}, + "range":[261,268], + "name":"p", + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":14,"column":16},"end":{"line":14,"column":22}}, + "range":[262,268], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":14,"column":18},"end":{"line":14,"column":22}}, + "range":[264,268] + } + }, + "optional":false + } + ], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":14,"column":30},"end":{"line":14,"column":32}}, + "range":[276,278], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":14,"column":23},"end":{"line":14,"column":29}}, + "range":[269,275], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":14,"column":25},"end":{"line":14,"column":29}}, + "range":[271,275] + } + }, + "typeParameters":null + }, + "kind":"set", + "method":false, + "shorthand":false, + "computed":false + } + ] + } + } + ], + "kind":"let" + }, + { + "type":"TypeAlias", + "loc":{"source":null,"start":{"line":16,"column":0},"end":{"line":18,"column":2}}, + "range":[282,343], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":16,"column":5},"end":{"line":16,"column":24}}, + "range":[287,306], + "name":"AbstractNamedSetter", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "right":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":16,"column":27},"end":{"line":18,"column":1}}, + "range":[309,342], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":17,"column":2},"end":{"line":17,"column":29}}, + "range":[313,340], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":17,"column":6},"end":{"line":17,"column":14}}, + "range":[317,325], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":17,"column":2},"end":{"line":17,"column":29}}, + "range":[313,340], + "params":[ + { + "type":"FunctionTypeParam", + "loc":{"source":null,"start":{"line":17,"column":15},"end":{"line":17,"column":22}}, + "range":[326,333], + "name":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":17,"column":15},"end":{"line":17,"column":16}}, + "range":[326,327], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":17,"column":18},"end":{"line":17,"column":22}}, + "range":[329,333] + }, + "optional":false + } + ], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":17,"column":25},"end":{"line":17,"column":29}}, + "range":[336,340] + }, + "rest":null, + "typeParameters":null + }, + "method":false, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"set" + } + ], + "indexers":[], + "callProperties":[] + } + }, + { + "type":"VariableDeclaration", + "loc":{"source":null,"start":{"line":19,"column":0},"end":{"line":21,"column":2}}, + "range":[344,390], + "declarations":[ + { + "type":"VariableDeclarator", + "loc":{"source":null,"start":{"line":19,"column":4},"end":{"line":21,"column":1}}, + "range":[348,389], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":19,"column":4},"end":{"line":19,"column":25}}, + "range":[348,369], + "name":"abstractNamedProperty", + "typeAnnotation":null, + "optional":false + }, + "init":{ + "type":"ObjectExpression", + "loc":{"source":null,"start":{"line":19,"column":28},"end":{"line":21,"column":1}}, + "range":[372,389], + "properties":[ + { + "type":"Property", + "loc":{"source":null,"start":{"line":20,"column":2},"end":{"line":20,"column":13}}, + "range":[376,387], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":20,"column":2},"end":{"line":20,"column":10}}, + "range":[376,384], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"Literal", + "loc":{"source":null,"start":{"line":20,"column":12},"end":{"line":20,"column":13}}, + "range":[386,387], + "value":1, + "raw":"1" + }, + "kind":"init", + "method":false, + "shorthand":false, + "computed":false + } + ] + } + } + ], + "kind":"let" + }, + { + "type":"TypeAlias", + "loc":{"source":null,"start":{"line":22,"column":0},"end":{"line":24,"column":2}}, + "range":[391,444], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":22,"column":5},"end":{"line":22,"column":27}}, + "range":[396,418], + "name":"AbstractNamedPropertyT", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "right":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":22,"column":30},"end":{"line":24,"column":1}}, + "range":[421,443], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":23,"column":2},"end":{"line":23,"column":18}}, + "range":[425,441], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":23,"column":2},"end":{"line":23,"column":10}}, + "range":[425,433], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"NumberTypeAnnotation", + "loc":{"source":null,"start":{"line":23,"column":12},"end":{"line":23,"column":18}}, + "range":[435,441] + }, + "method":false, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + } + } + ], + "comments":[] +} diff --git a/src/parser/test/flow/abstract_class/private.js b/src/parser/test/flow/abstract_class/private.js new file mode 100644 index 00000000000..f5751d78e1c --- /dev/null +++ b/src/parser/test/flow/abstract_class/private.js @@ -0,0 +1,9 @@ +class AbstractPrivateMethod { abstract #m(): void; } //Error +declare class AbstractPrivateMethodDecl { abstract #m(): void; } //Error +class StaticAbstractPrivateMethod { abstract static #m(): void; } //Error +declare class StaticAbstractPrivateMethodDecl { abstract static #m(): void; } //Error + +class AbstractPrivateProperty { abstract #m: void; } //Error +declare class AbstractPrivatePropertyDecl { abstract #m: void; } //Error +class StaticAbstractPrivateProperty { abstract static #m: void; } //Error +declare class StaticAbstractPrivatePropertyDecl { abstract static #m: void; } //Error diff --git a/src/parser/test/flow/abstract_class/private.tree.json b/src/parser/test/flow/abstract_class/private.tree.json new file mode 100644 index 00000000000..305a6c8fddc --- /dev/null +++ b/src/parser/test/flow/abstract_class/private.tree.json @@ -0,0 +1,533 @@ +{ + "errors":[ + { + "loc":{"source":null,"start":{"line":1,"column":48},"end":{"line":1,"column":75}}, + "message":"Abstract privates are not allowed." + }, + { + "loc":{"source":null,"start":{"line":2,"column":64},"end":{"line":2,"column":66}}, + "message":"Private fields can only be referenced from within a class." + }, + { + "loc":{"source":null,"start":{"line":3,"column":48},"end":{"line":3,"column":75}}, + "message":"Abstract privates are not allowed." + }, + { + "loc":{"source":null,"start":{"line":4,"column":64},"end":{"line":4,"column":66}}, + "message":"Private fields can only be referenced from within a class." + }, + { + "loc":{"source":null,"start":{"line":6,"column":50},"end":{"line":6,"column":75}}, + "message":"Abstract privates are not allowed." + }, + { + "loc":{"source":null,"start":{"line":6,"column":50},"end":{"line":6,"column":75}}, + "message":"Abstract properties are not allowed." + }, + { + "loc":{"source":null,"start":{"line":7,"column":66},"end":{"line":7,"column":68}}, + "message":"Private fields can only be referenced from within a class." + }, + { + "loc":{"source":null,"start":{"line":7,"column":50},"end":{"line":7,"column":74}}, + "message":"Abstract properties are not allowed." + }, + { + "loc":{"source":null,"start":{"line":8,"column":50},"end":{"line":8,"column":75}}, + "message":"Abstract privates are not allowed." + }, + { + "loc":{"source":null,"start":{"line":8,"column":50},"end":{"line":8,"column":75}}, + "message":"Abstract properties are not allowed." + }, + { + "loc":{"source":null,"start":{"line":9,"column":66},"end":{"line":9,"column":68}}, + "message":"Private fields can only be referenced from within a class." + }, + { + "loc":{"source":null,"start":{"line":9,"column":50},"end":{"line":9,"column":74}}, + "message":"Abstract properties are not allowed." + } + ], + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":9,"column":77}}, + "range":[0,680], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":77}}, + "range":[0,77], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":27}}, + "range":[6,27], + "name":"AbstractPrivateMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":46},"end":{"line":1,"column":77}}, + "range":[46,77], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":48},"end":{"line":1,"column":75}}, + "range":[48,75], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":65},"end":{"line":1,"column":66}}, + "range":[65,66], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":66},"end":{"line":1,"column":75}}, + "range":[66,75], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":70},"end":{"line":1,"column":74}}, + "range":[70,74] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":77}}, + "range":[86,163], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":14},"end":{"line":2,"column":39}}, + "range":[100,125], + "name":"AbstractPrivateMethodDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":46},"end":{"line":2,"column":77}}, + "range":[132,163], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":2,"column":48},"end":{"line":2,"column":74}}, + "range":[134,160], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":65},"end":{"line":2,"column":66}}, + "range":[151,152], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":48},"end":{"line":2,"column":74}}, + "range":[134,160], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":70},"end":{"line":2,"column":74}}, + "range":[156,160] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":77}}, + "range":[172,249], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":6},"end":{"line":3,"column":33}}, + "range":[178,205], + "name":"StaticAbstractPrivateMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":3,"column":46},"end":{"line":3,"column":77}}, + "range":[218,249], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":3,"column":48},"end":{"line":3,"column":75}}, + "range":[220,247], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":65},"end":{"line":3,"column":66}}, + "range":[237,238], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":66},"end":{"line":3,"column":75}}, + "range":[238,247], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":70},"end":{"line":3,"column":74}}, + "range":[242,246] + }, + "rest":null, + "typeParameters":null + }, + "static":true + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":77}}, + "range":[258,335], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":14},"end":{"line":4,"column":45}}, + "range":[272,303], + "name":"StaticAbstractPrivateMethodDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":46},"end":{"line":4,"column":77}}, + "range":[304,335], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":4,"column":48},"end":{"line":4,"column":74}}, + "range":[306,332], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":65},"end":{"line":4,"column":66}}, + "range":[323,324], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":48},"end":{"line":4,"column":74}}, + "range":[306,332], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":70},"end":{"line":4,"column":74}}, + "range":[328,332] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":true, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":6,"column":0},"end":{"line":6,"column":77}}, + "range":[345,422], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":6},"end":{"line":6,"column":29}}, + "range":[351,374], + "name":"AbstractPrivateProperty", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":6,"column":48},"end":{"line":6,"column":77}}, + "range":[393,422], + "body":[ + { + "type":"ClassPrivateProperty", + "loc":{"source":null,"start":{"line":6,"column":50},"end":{"line":6,"column":75}}, + "range":[395,420], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":67},"end":{"line":6,"column":68}}, + "range":[412,413], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":68},"end":{"line":6,"column":74}}, + "range":[413,419], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":70},"end":{"line":6,"column":74}}, + "range":[415,419] + } + }, + "static":false, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":7,"column":0},"end":{"line":7,"column":77}}, + "range":[431,508], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":14},"end":{"line":7,"column":41}}, + "range":[445,472], + "name":"AbstractPrivatePropertyDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":48},"end":{"line":7,"column":77}}, + "range":[479,508], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":7,"column":50},"end":{"line":7,"column":74}}, + "range":[481,505], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":67},"end":{"line":7,"column":68}}, + "range":[498,499], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":70},"end":{"line":7,"column":74}}, + "range":[501,505] + }, + "method":false, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":8,"column":0},"end":{"line":8,"column":77}}, + "range":[517,594], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":6},"end":{"line":8,"column":35}}, + "range":[523,552], + "name":"StaticAbstractPrivateProperty", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":8,"column":48},"end":{"line":8,"column":77}}, + "range":[565,594], + "body":[ + { + "type":"ClassPrivateProperty", + "loc":{"source":null,"start":{"line":8,"column":50},"end":{"line":8,"column":75}}, + "range":[567,592], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":67},"end":{"line":8,"column":68}}, + "range":[584,585], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":68},"end":{"line":8,"column":74}}, + "range":[585,591], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":70},"end":{"line":8,"column":74}}, + "range":[587,591] + } + }, + "static":true, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":9,"column":0},"end":{"line":9,"column":77}}, + "range":[603,680], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":14},"end":{"line":9,"column":47}}, + "range":[617,650], + "name":"StaticAbstractPrivatePropertyDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":48},"end":{"line":9,"column":77}}, + "range":[651,680], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":9,"column":50},"end":{"line":9,"column":74}}, + "range":[653,677], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":67},"end":{"line":9,"column":68}}, + "range":[670,671], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":70},"end":{"line":9,"column":74}}, + "range":[673,677] + }, + "method":false, + "optional":false, + "abstract":false, + "static":true, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + } + ], + "comments":[ + { + "type":"Line", + "loc":{"source":null,"start":{"line":1,"column":78},"end":{"line":1,"column":85}}, + "range":[78,85], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":2,"column":78},"end":{"line":2,"column":85}}, + "range":[164,171], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":3,"column":78},"end":{"line":3,"column":85}}, + "range":[250,257], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":4,"column":78},"end":{"line":4,"column":85}}, + "range":[336,343], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":6,"column":78},"end":{"line":6,"column":85}}, + "range":[423,430], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":7,"column":78},"end":{"line":7,"column":85}}, + "range":[509,516], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":8,"column":78},"end":{"line":8,"column":85}}, + "range":[595,602], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":9,"column":78},"end":{"line":9,"column":85}}, + "range":[681,688], + "value":"Error" + } + ] +} diff --git a/src/parser/test/flow/abstract_class/property.js b/src/parser/test/flow/abstract_class/property.js new file mode 100644 index 00000000000..f494081e816 --- /dev/null +++ b/src/parser/test/flow/abstract_class/property.js @@ -0,0 +1,5 @@ +class AbstractProperty { abstract m: void; } //Error +class StaticAbstractProperty { abstract static m: void; } //Error +declare class AbstractPropertyDecl { abstract m: void; } //Error +declare class StaticAbstractPropertyDecl { abstract static m: void; } //Error + diff --git a/src/parser/test/flow/abstract_class/property.tree.json b/src/parser/test/flow/abstract_class/property.tree.json new file mode 100644 index 00000000000..640b47f9f71 --- /dev/null +++ b/src/parser/test/flow/abstract_class/property.tree.json @@ -0,0 +1,253 @@ +{ + "errors":[ + { + "loc":{"source":null,"start":{"line":1,"column":43},"end":{"line":1,"column":67}}, + "message":"Abstract properties are not allowed." + }, + { + "loc":{"source":null,"start":{"line":2,"column":43},"end":{"line":2,"column":67}}, + "message":"Abstract properties are not allowed." + }, + { + "loc":{"source":null,"start":{"line":3,"column":43},"end":{"line":3,"column":66}}, + "message":"Abstract properties are not allowed." + }, + { + "loc":{"source":null,"start":{"line":4,"column":43},"end":{"line":4,"column":66}}, + "message":"Abstract properties are not allowed." + } + ], + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":4,"column":69}}, + "range":[0,303], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":69}}, + "range":[0,69], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":30}}, + "range":[14,30], + "name":"AbstractProperty", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":41},"end":{"line":1,"column":69}}, + "range":[41,69], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":1,"column":43},"end":{"line":1,"column":67}}, + "range":[43,67], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":59},"end":{"line":1,"column":60}}, + "range":[59,60], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":60},"end":{"line":1,"column":66}}, + "range":[60,66], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":62},"end":{"line":1,"column":66}}, + "range":[62,66] + } + }, + "computed":false, + "static":false, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":69}}, + "range":[78,147], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":14},"end":{"line":2,"column":36}}, + "range":[92,114], + "name":"StaticAbstractProperty", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":2,"column":41},"end":{"line":2,"column":69}}, + "range":[119,147], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":2,"column":43},"end":{"line":2,"column":67}}, + "range":[121,145], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":59},"end":{"line":2,"column":60}}, + "range":[137,138], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":60},"end":{"line":2,"column":66}}, + "range":[138,144], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":62},"end":{"line":2,"column":66}}, + "range":[140,144] + } + }, + "computed":false, + "static":true, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":69}}, + "range":[156,225], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":14},"end":{"line":3,"column":34}}, + "range":[170,190], + "name":"AbstractPropertyDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":41},"end":{"line":3,"column":69}}, + "range":[197,225], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":3,"column":43},"end":{"line":3,"column":66}}, + "range":[199,222], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":59},"end":{"line":3,"column":60}}, + "range":[215,216], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":62},"end":{"line":3,"column":66}}, + "range":[218,222] + }, + "method":false, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":69}}, + "range":[234,303], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":14},"end":{"line":4,"column":40}}, + "range":[248,274], + "name":"StaticAbstractPropertyDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":41},"end":{"line":4,"column":69}}, + "range":[275,303], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":4,"column":43},"end":{"line":4,"column":66}}, + "range":[277,300], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":59},"end":{"line":4,"column":60}}, + "range":[293,294], + "name":"m", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":62},"end":{"line":4,"column":66}}, + "range":[296,300] + }, + "method":false, + "optional":false, + "abstract":false, + "static":true, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + } + ], + "comments":[ + { + "type":"Line", + "loc":{"source":null,"start":{"line":1,"column":70},"end":{"line":1,"column":77}}, + "range":[70,77], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":2,"column":70},"end":{"line":2,"column":77}}, + "range":[148,155], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":3,"column":70},"end":{"line":3,"column":77}}, + "range":[226,233], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":4,"column":70},"end":{"line":4,"column":77}}, + "range":[304,311], + "value":"Error" + } + ] +} diff --git a/src/parser/test/flow/abstract_class/set.js b/src/parser/test/flow/abstract_class/set.js new file mode 100644 index 00000000000..c52188b1983 --- /dev/null +++ b/src/parser/test/flow/abstract_class/set.js @@ -0,0 +1,14 @@ +class AbstractSetMethod { abstract set(p: void): void; } +class AbstractStaticSetMethod { abstract static set(p: void): void; } +declare class AbstractSetMethodDecl { abstract set(p: void): void; } +declare class AbstractStaticSetMethodDecl { abstract static set(p: void): void; } + +class AbstractSetter { abstract set p(p: void): void {} } //Error +class AbstractStaticSetter { abstract static set p(p: void): void {} } //Error +declare class AbstractSetterDecl { abstract set p(p: void): void; } //Error +declare class AbstractStaticSetterDecl { abstract static set p(p: void): void; } //Error + +class SetterNamedAbstract { set abstract(p: void): void {} } +class StaticSetterNamedAbstract { static set abstract(p: void): void {} } +declare class SetterNamedAbstractDecl { set abstract(p: void): void; } +declare class StaticSetterNamedAbstractDecl { static set abstract(p: void): void; } diff --git a/src/parser/test/flow/abstract_class/set.options.json b/src/parser/test/flow/abstract_class/set.options.json new file mode 100644 index 00000000000..ca050bc545d --- /dev/null +++ b/src/parser/test/flow/abstract_class/set.options.json @@ -0,0 +1,4 @@ +{ + "esproposal_class_static_fields": true, + "esproposal_class_instance_fields": true +} diff --git a/src/parser/test/flow/abstract_class/set.tree.json b/src/parser/test/flow/abstract_class/set.tree.json new file mode 100644 index 00000000000..70687e53fd8 --- /dev/null +++ b/src/parser/test/flow/abstract_class/set.tree.json @@ -0,0 +1,1025 @@ +{ + "errors":[ + { + "loc":{"source":null,"start":{"line":6,"column":41},"end":{"line":6,"column":80}}, + "message":"Abstract setters are not allowed." + }, + { + "loc":{"source":null,"start":{"line":7,"column":41},"end":{"line":7,"column":80}}, + "message":"Abstract setters are not allowed." + }, + { + "loc":{"source":null,"start":{"line":8,"column":41},"end":{"line":8,"column":77}}, + "message":"Abstract setters are not allowed." + }, + { + "loc":{"source":null,"start":{"line":9,"column":41},"end":{"line":9,"column":77}}, + "message":"Abstract setters are not allowed." + } + ], + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":14,"column":85}}, + "range":[0,1037], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":81}}, + "range":[0,81], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":31}}, + "range":[14,31], + "name":"AbstractSetMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":42},"end":{"line":1,"column":81}}, + "range":[42,81], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":44},"end":{"line":1,"column":79}}, + "range":[44,79], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":60},"end":{"line":1,"column":63}}, + "range":[60,63], + "name":"set", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":63},"end":{"line":1,"column":79}}, + "range":[63,79], + "params":[ + { + "type":"FunctionTypeParam", + "loc":{"source":null,"start":{"line":1,"column":64},"end":{"line":1,"column":71}}, + "range":[64,71], + "name":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":64},"end":{"line":1,"column":65}}, + "range":[64,65], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":67},"end":{"line":1,"column":71}}, + "range":[67,71] + }, + "optional":false + } + ], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":74},"end":{"line":1,"column":78}}, + "range":[74,78] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":81}}, + "range":[82,163], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":14},"end":{"line":2,"column":37}}, + "range":[96,119], + "name":"AbstractStaticSetMethod", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":2,"column":42},"end":{"line":2,"column":81}}, + "range":[124,163], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":2,"column":44},"end":{"line":2,"column":79}}, + "range":[126,161], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":60},"end":{"line":2,"column":63}}, + "range":[142,145], + "name":"set", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":63},"end":{"line":2,"column":79}}, + "range":[145,161], + "params":[ + { + "type":"FunctionTypeParam", + "loc":{"source":null,"start":{"line":2,"column":64},"end":{"line":2,"column":71}}, + "range":[146,153], + "name":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":64},"end":{"line":2,"column":65}}, + "range":[146,147], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":67},"end":{"line":2,"column":71}}, + "range":[149,153] + }, + "optional":false + } + ], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":74},"end":{"line":2,"column":78}}, + "range":[156,160] + }, + "rest":null, + "typeParameters":null + }, + "static":true + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":81}}, + "range":[164,245], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":14},"end":{"line":3,"column":35}}, + "range":[178,199], + "name":"AbstractSetMethodDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":42},"end":{"line":3,"column":81}}, + "range":[206,245], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":3,"column":44},"end":{"line":3,"column":78}}, + "range":[208,242], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":60},"end":{"line":3,"column":63}}, + "range":[224,227], + "name":"set", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":44},"end":{"line":3,"column":78}}, + "range":[208,242], + "params":[ + { + "type":"FunctionTypeParam", + "loc":{"source":null,"start":{"line":3,"column":64},"end":{"line":3,"column":71}}, + "range":[228,235], + "name":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":64},"end":{"line":3,"column":65}}, + "range":[228,229], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":67},"end":{"line":3,"column":71}}, + "range":[231,235] + }, + "optional":false + } + ], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":74},"end":{"line":3,"column":78}}, + "range":[238,242] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":81}}, + "range":[246,327], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":14},"end":{"line":4,"column":41}}, + "range":[260,287], + "name":"AbstractStaticSetMethodDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":42},"end":{"line":4,"column":81}}, + "range":[288,327], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":4,"column":44},"end":{"line":4,"column":78}}, + "range":[290,324], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":60},"end":{"line":4,"column":63}}, + "range":[306,309], + "name":"set", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":44},"end":{"line":4,"column":78}}, + "range":[290,324], + "params":[ + { + "type":"FunctionTypeParam", + "loc":{"source":null,"start":{"line":4,"column":64},"end":{"line":4,"column":71}}, + "range":[310,317], + "name":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":4,"column":64},"end":{"line":4,"column":65}}, + "range":[310,311], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":67},"end":{"line":4,"column":71}}, + "range":[313,317] + }, + "optional":false + } + ], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":4,"column":74},"end":{"line":4,"column":78}}, + "range":[320,324] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":true, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":6,"column":0},"end":{"line":6,"column":82}}, + "range":[329,411], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":14},"end":{"line":6,"column":28}}, + "range":[343,357], + "name":"AbstractSetter", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":6,"column":39},"end":{"line":6,"column":82}}, + "range":[368,411], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":6,"column":41},"end":{"line":6,"column":80}}, + "range":[370,409], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":61},"end":{"line":6,"column":62}}, + "range":[390,391], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":6,"column":62},"end":{"line":6,"column":80}}, + "range":[391,409], + "id":null, + "params":[ + { + "type":"Identifier", + "loc":{"source":null,"start":{"line":6,"column":63},"end":{"line":6,"column":70}}, + "range":[392,399], + "name":"p", + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":64},"end":{"line":6,"column":70}}, + "range":[393,399], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":66},"end":{"line":6,"column":70}}, + "range":[395,399] + } + }, + "optional":false + } + ], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":6,"column":78},"end":{"line":6,"column":80}}, + "range":[407,409], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":71},"end":{"line":6,"column":77}}, + "range":[400,406], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":6,"column":73},"end":{"line":6,"column":77}}, + "range":[402,406] + } + }, + "typeParameters":null + }, + "kind":"set", + "static":false, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":7,"column":0},"end":{"line":7,"column":82}}, + "range":[420,502], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":14},"end":{"line":7,"column":34}}, + "range":[434,454], + "name":"AbstractStaticSetter", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":7,"column":39},"end":{"line":7,"column":82}}, + "range":[459,502], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":7,"column":41},"end":{"line":7,"column":80}}, + "range":[461,500], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":61},"end":{"line":7,"column":62}}, + "range":[481,482], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":7,"column":62},"end":{"line":7,"column":80}}, + "range":[482,500], + "id":null, + "params":[ + { + "type":"Identifier", + "loc":{"source":null,"start":{"line":7,"column":63},"end":{"line":7,"column":70}}, + "range":[483,490], + "name":"p", + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":64},"end":{"line":7,"column":70}}, + "range":[484,490], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":66},"end":{"line":7,"column":70}}, + "range":[486,490] + } + }, + "optional":false + } + ], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":7,"column":78},"end":{"line":7,"column":80}}, + "range":[498,500], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":71},"end":{"line":7,"column":77}}, + "range":[491,497], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":7,"column":73},"end":{"line":7,"column":77}}, + "range":[493,497] + } + }, + "typeParameters":null + }, + "kind":"set", + "static":true, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":8,"column":0},"end":{"line":8,"column":82}}, + "range":[511,593], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":14},"end":{"line":8,"column":32}}, + "range":[525,543], + "name":"AbstractSetterDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":39},"end":{"line":8,"column":82}}, + "range":[550,593], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":8,"column":41},"end":{"line":8,"column":77}}, + "range":[552,588], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":61},"end":{"line":8,"column":62}}, + "range":[572,573], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":41},"end":{"line":8,"column":77}}, + "range":[552,588], + "params":[ + { + "type":"FunctionTypeParam", + "loc":{"source":null,"start":{"line":8,"column":63},"end":{"line":8,"column":70}}, + "range":[574,581], + "name":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":8,"column":63},"end":{"line":8,"column":64}}, + "range":[574,575], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":66},"end":{"line":8,"column":70}}, + "range":[577,581] + }, + "optional":false + } + ], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":8,"column":73},"end":{"line":8,"column":77}}, + "range":[584,588] + }, + "rest":null, + "typeParameters":null + }, + "method":false, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"set" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":9,"column":0},"end":{"line":9,"column":82}}, + "range":[602,684], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":14},"end":{"line":9,"column":38}}, + "range":[616,640], + "name":"AbstractStaticSetterDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":39},"end":{"line":9,"column":82}}, + "range":[641,684], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":9,"column":41},"end":{"line":9,"column":77}}, + "range":[643,679], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":61},"end":{"line":9,"column":62}}, + "range":[663,664], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":41},"end":{"line":9,"column":77}}, + "range":[643,679], + "params":[ + { + "type":"FunctionTypeParam", + "loc":{"source":null,"start":{"line":9,"column":63},"end":{"line":9,"column":70}}, + "range":[665,672], + "name":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":9,"column":63},"end":{"line":9,"column":64}}, + "range":[665,666], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":66},"end":{"line":9,"column":70}}, + "range":[668,672] + }, + "optional":false + } + ], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":9,"column":73},"end":{"line":9,"column":77}}, + "range":[675,679] + }, + "rest":null, + "typeParameters":null + }, + "method":false, + "optional":false, + "abstract":false, + "static":true, + "variance":null, + "kind":"set" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":11,"column":0},"end":{"line":11,"column":85}}, + "range":[694,779], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":11,"column":14},"end":{"line":11,"column":33}}, + "range":[708,727], + "name":"SetterNamedAbstract", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":11,"column":44},"end":{"line":11,"column":85}}, + "range":[738,779], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":11,"column":53},"end":{"line":11,"column":83}}, + "range":[747,777], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":11,"column":57},"end":{"line":11,"column":65}}, + "range":[751,759], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":11,"column":65},"end":{"line":11,"column":83}}, + "range":[759,777], + "id":null, + "params":[ + { + "type":"Identifier", + "loc":{"source":null,"start":{"line":11,"column":66},"end":{"line":11,"column":73}}, + "range":[760,767], + "name":"p", + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":11,"column":67},"end":{"line":11,"column":73}}, + "range":[761,767], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":11,"column":69},"end":{"line":11,"column":73}}, + "range":[763,767] + } + }, + "optional":false + } + ], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":11,"column":81},"end":{"line":11,"column":83}}, + "range":[775,777], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":11,"column":74},"end":{"line":11,"column":80}}, + "range":[768,774], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":11,"column":76},"end":{"line":11,"column":80}}, + "range":[770,774] + } + }, + "typeParameters":null + }, + "kind":"set", + "static":false, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":12,"column":0},"end":{"line":12,"column":85}}, + "range":[780,865], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":12,"column":14},"end":{"line":12,"column":39}}, + "range":[794,819], + "name":"StaticSetterNamedAbstract", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":12,"column":44},"end":{"line":12,"column":85}}, + "range":[824,865], + "body":[ + { + "type":"MethodDefinition", + "loc":{"source":null,"start":{"line":12,"column":46},"end":{"line":12,"column":83}}, + "range":[826,863], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":12,"column":57},"end":{"line":12,"column":65}}, + "range":[837,845], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionExpression", + "loc":{"source":null,"start":{"line":12,"column":65},"end":{"line":12,"column":83}}, + "range":[845,863], + "id":null, + "params":[ + { + "type":"Identifier", + "loc":{"source":null,"start":{"line":12,"column":66},"end":{"line":12,"column":73}}, + "range":[846,853], + "name":"p", + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":12,"column":67},"end":{"line":12,"column":73}}, + "range":[847,853], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":12,"column":69},"end":{"line":12,"column":73}}, + "range":[849,853] + } + }, + "optional":false + } + ], + "body":{ + "type":"BlockStatement", + "loc":{"source":null,"start":{"line":12,"column":81},"end":{"line":12,"column":83}}, + "range":[861,863], + "body":[] + }, + "async":false, + "generator":false, + "predicate":null, + "expression":false, + "returnType":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":12,"column":74},"end":{"line":12,"column":80}}, + "range":[854,860], + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":12,"column":76},"end":{"line":12,"column":80}}, + "range":[856,860] + } + }, + "typeParameters":null + }, + "kind":"set", + "static":true, + "computed":false, + "decorators":[] + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":13,"column":0},"end":{"line":13,"column":85}}, + "range":[866,951], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":13,"column":14},"end":{"line":13,"column":37}}, + "range":[880,903], + "name":"SetterNamedAbstractDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":13,"column":44},"end":{"line":13,"column":85}}, + "range":[910,951], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":13,"column":53},"end":{"line":13,"column":80}}, + "range":[919,946], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":13,"column":57},"end":{"line":13,"column":65}}, + "range":[923,931], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":13,"column":53},"end":{"line":13,"column":80}}, + "range":[919,946], + "params":[ + { + "type":"FunctionTypeParam", + "loc":{"source":null,"start":{"line":13,"column":66},"end":{"line":13,"column":73}}, + "range":[932,939], + "name":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":13,"column":66},"end":{"line":13,"column":67}}, + "range":[932,933], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":13,"column":69},"end":{"line":13,"column":73}}, + "range":[935,939] + }, + "optional":false + } + ], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":13,"column":76},"end":{"line":13,"column":80}}, + "range":[942,946] + }, + "rest":null, + "typeParameters":null + }, + "method":false, + "optional":false, + "abstract":false, + "static":false, + "variance":null, + "kind":"set" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":14,"column":0},"end":{"line":14,"column":85}}, + "range":[952,1037], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":14,"column":14},"end":{"line":14,"column":43}}, + "range":[966,995], + "name":"StaticSetterNamedAbstractDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":14,"column":44},"end":{"line":14,"column":85}}, + "range":[996,1037], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":14,"column":46},"end":{"line":14,"column":80}}, + "range":[998,1032], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":14,"column":57},"end":{"line":14,"column":65}}, + "range":[1009,1017], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":14,"column":46},"end":{"line":14,"column":80}}, + "range":[998,1032], + "params":[ + { + "type":"FunctionTypeParam", + "loc":{"source":null,"start":{"line":14,"column":66},"end":{"line":14,"column":73}}, + "range":[1018,1025], + "name":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":14,"column":66},"end":{"line":14,"column":67}}, + "range":[1018,1019], + "name":"p", + "typeAnnotation":null, + "optional":false + }, + "typeAnnotation":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":14,"column":69},"end":{"line":14,"column":73}}, + "range":[1021,1025] + }, + "optional":false + } + ], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":14,"column":76},"end":{"line":14,"column":80}}, + "range":[1028,1032] + }, + "rest":null, + "typeParameters":null + }, + "method":false, + "optional":false, + "abstract":false, + "static":true, + "variance":null, + "kind":"set" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + } + ], + "comments":[ + { + "type":"Line", + "loc":{"source":null,"start":{"line":6,"column":83},"end":{"line":6,"column":90}}, + "range":[412,419], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":7,"column":83},"end":{"line":7,"column":90}}, + "range":[503,510], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":8,"column":83},"end":{"line":8,"column":90}}, + "range":[594,601], + "value":"Error" + }, + { + "type":"Line", + "loc":{"source":null,"start":{"line":9,"column":83},"end":{"line":9,"column":90}}, + "range":[685,692], + "value":"Error" + } + ] +} diff --git a/src/parser/test/flow/abstract_class/signature.js b/src/parser/test/flow/abstract_class/signature.js new file mode 100644 index 00000000000..5cf67aa3353 --- /dev/null +++ b/src/parser/test/flow/abstract_class/signature.js @@ -0,0 +1,3 @@ +class Foo { abstract myMethod(SomeType): void; } +class Bar { abstract static myMethod(number): void; } +class Baz { abstract myMethod(SomeType); } // Error, Missing return type diff --git a/src/parser/test/flow/abstract_class/signature.tree.json b/src/parser/test/flow/abstract_class/signature.tree.json new file mode 100644 index 00000000000..18b3be78e8d --- /dev/null +++ b/src/parser/test/flow/abstract_class/signature.tree.json @@ -0,0 +1,244 @@ +{ + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":3,"column":42}}, + "range":[0,145], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":48}}, + "range":[0,48], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":9}}, + "range":[6,9], + "name":"Foo", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":10},"end":{"line":1,"column":48}}, + "range":[10,48], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":12},"end":{"line":1,"column":46}}, + "range":[12,46], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":29}}, + "range":[21,29], + "name":"myMethod", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":46}}, + "range":[29,46], + "params":[ + { + "type":"FunctionTypeParam", + "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":38}}, + "range":[30,38], + "name":null, + "typeAnnotation":{ + "type":"GenericTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":38}}, + "range":[30,38], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":38}}, + "range":[30,38], + "name":"SomeType", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null + }, + "optional":false + } + ], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":41},"end":{"line":1,"column":45}}, + "range":[41,45] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":53}}, + "range":[49,102], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":6},"end":{"line":2,"column":9}}, + "range":[55,58], + "name":"Bar", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":2,"column":10},"end":{"line":2,"column":53}}, + "range":[59,102], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":2,"column":12},"end":{"line":2,"column":51}}, + "range":[61,100], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":28},"end":{"line":2,"column":36}}, + "range":[77,85], + "name":"myMethod", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":36},"end":{"line":2,"column":51}}, + "range":[85,100], + "params":[ + { + "type":"FunctionTypeParam", + "loc":{"source":null,"start":{"line":2,"column":37},"end":{"line":2,"column":43}}, + "range":[86,92], + "name":null, + "typeAnnotation":{ + "type":"NumberTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":37},"end":{"line":2,"column":43}}, + "range":[86,92] + }, + "optional":false + } + ], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":46},"end":{"line":2,"column":50}}, + "range":[95,99] + }, + "rest":null, + "typeParameters":null + }, + "static":true + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":42}}, + "range":[103,145], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":6},"end":{"line":3,"column":9}}, + "range":[109,112], + "name":"Baz", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":3,"column":10},"end":{"line":3,"column":42}}, + "range":[113,145], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":3,"column":12},"end":{"line":3,"column":40}}, + "range":[115,143], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":21},"end":{"line":3,"column":29}}, + "range":[124,132], + "name":"myMethod", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":29},"end":{"line":3,"column":40}}, + "range":[132,143], + "params":[ + { + "type":"FunctionTypeParam", + "loc":{"source":null,"start":{"line":3,"column":30},"end":{"line":3,"column":38}}, + "range":[133,141], + "name":null, + "typeAnnotation":{ + "type":"GenericTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":30},"end":{"line":3,"column":38}}, + "range":[133,141], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":3,"column":30},"end":{"line":3,"column":38}}, + "range":[133,141], + "name":"SomeType", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null + }, + "optional":false + } + ], + "async":false, + "generator":false, + "returnType":{ + "type":"AnyTypeAnnotation", + "loc":{"source":null,"start":{"line":3,"column":41},"end":{"line":3,"column":42}}, + "range":[144,145] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + } + ], + "comments":[ + { + "type":"Line", + "loc":{"source":null,"start":{"line":3,"column":43},"end":{"line":3,"column":72}}, + "range":[146,175], + "value":" Error, Missing return type" + } + ], + "errors":[ + { + "loc":{"source":null,"start":{"line":3,"column":39},"end":{"line":3,"column":40}}, + "message":"Unexpected token ;" + }, + { + "loc":{"source":null,"start":{"line":3,"column":41},"end":{"line":3,"column":42}}, + "message":"Unexpected token }" + } + ] +} diff --git a/src/parser/test/flow/abstract_class/static_name.js b/src/parser/test/flow/abstract_class/static_name.js new file mode 100644 index 00000000000..82fc00ff3ab --- /dev/null +++ b/src/parser/test/flow/abstract_class/static_name.js @@ -0,0 +1,2 @@ +class NameNamedAbstract { abstract name(): string; } +class NameNamedAbstractStatic { abstract static name(): string; } //Error diff --git a/src/parser/test/flow/abstract_class/static_name.tree.json b/src/parser/test/flow/abstract_class/static_name.tree.json new file mode 100644 index 00000000000..902bd2786c5 --- /dev/null +++ b/src/parser/test/flow/abstract_class/static_name.tree.json @@ -0,0 +1,129 @@ +{ + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":2,"column":65}}, + "range":[0,131], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":65}}, + "range":[0,65], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":23}}, + "range":[6,23], + "name":"NameNamedAbstract", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":65}}, + "range":[30,65], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":32},"end":{"line":1,"column":63}}, + "range":[32,63], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":48},"end":{"line":1,"column":52}}, + "range":[48,52], + "name":"name", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":52},"end":{"line":1,"column":63}}, + "range":[52,63], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"StringTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":56},"end":{"line":1,"column":62}}, + "range":[56,62] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":65}}, + "range":[66,131], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":6},"end":{"line":2,"column":29}}, + "range":[72,95], + "name":"NameNamedAbstractStatic", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":2,"column":30},"end":{"line":2,"column":65}}, + "range":[96,131], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":2,"column":32},"end":{"line":2,"column":63}}, + "range":[98,129], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":48},"end":{"line":2,"column":52}}, + "range":[114,118], + "name":"name", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":52},"end":{"line":2,"column":63}}, + "range":[118,129], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"StringTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":56},"end":{"line":2,"column":62}}, + "range":[122,128] + }, + "rest":null, + "typeParameters":null + }, + "static":true + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + } + ], + "comments":[ + { + "type":"Line", + "loc":{"source":null,"start":{"line":2,"column":66},"end":{"line":2,"column":73}}, + "range":[132,139], + "value":"Error" + } + ], + "errors":[ + { + "loc":{"source":null,"start":{"line":2,"column":32},"end":{"line":2,"column":63}}, + "message":"Abstract static `name` methods are not allowed." + } + ] +} diff --git a/src/parser/test/flow/abstract_class/static_named.js b/src/parser/test/flow/abstract_class/static_named.js new file mode 100644 index 00000000000..c944e99567c --- /dev/null +++ b/src/parser/test/flow/abstract_class/static_named.js @@ -0,0 +1,2 @@ +class StaticNamedAbstract { abstract static(): void; } +declare class StaticNamedAbstractDecl { abstract static(): void; } diff --git a/src/parser/test/flow/abstract_class/static_named.tree.json b/src/parser/test/flow/abstract_class/static_named.tree.json new file mode 100644 index 00000000000..0579d3bc22f --- /dev/null +++ b/src/parser/test/flow/abstract_class/static_named.tree.json @@ -0,0 +1,121 @@ +{ + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":2,"column":66}}, + "range":[0,133], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":66}}, + "range":[0,66], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":33}}, + "range":[14,33], + "name":"StaticNamedAbstract", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":38},"end":{"line":1,"column":66}}, + "range":[38,66], + "body":[ + { + "type":"AbstractMethodDefinition", + "loc":{"source":null,"start":{"line":1,"column":40},"end":{"line":1,"column":64}}, + "range":[40,64], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":49},"end":{"line":1,"column":55}}, + "range":[49,55], + "name":"static", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":55},"end":{"line":1,"column":64}}, + "range":[55,64], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":59},"end":{"line":1,"column":63}}, + "range":[59,63] + }, + "rest":null, + "typeParameters":null + }, + "static":false + } + ] + }, + "superClass":null, + "typeParameters":null, + "superTypeParameters":null, + "implements":[], + "decorators":[] + }, + { + "type":"DeclareClass", + "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":66}}, + "range":[67,133], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":14},"end":{"line":2,"column":37}}, + "range":[81,104], + "name":"StaticNamedAbstractDecl", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null, + "body":{ + "type":"ObjectTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":38},"end":{"line":2,"column":66}}, + "range":[105,133], + "exact":false, + "properties":[ + { + "type":"ObjectTypeProperty", + "loc":{"source":null,"start":{"line":2,"column":40},"end":{"line":2,"column":63}}, + "range":[107,130], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":2,"column":49},"end":{"line":2,"column":55}}, + "range":[116,122], + "name":"static", + "typeAnnotation":null, + "optional":false + }, + "value":{ + "type":"FunctionTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":40},"end":{"line":2,"column":63}}, + "range":[107,130], + "params":[], + "async":false, + "generator":false, + "returnType":{ + "type":"VoidTypeAnnotation", + "loc":{"source":null,"start":{"line":2,"column":59},"end":{"line":2,"column":63}}, + "range":[126,130] + }, + "rest":null, + "typeParameters":null + }, + "method":true, + "optional":false, + "abstract":true, + "static":false, + "variance":null, + "kind":"init" + } + ], + "indexers":[], + "callProperties":[] + }, + "extends":[] + } + ], + "comments":[] +} diff --git a/src/parser/test/flow/abstract_class/type.js b/src/parser/test/flow/abstract_class/type.js new file mode 100644 index 00000000000..c71e9d58169 --- /dev/null +++ b/src/parser/test/flow/abstract_class/type.js @@ -0,0 +1 @@ +class TypeParamNamedAbstract { x: abstract; } diff --git a/src/parser/test/flow/abstract_class/type.tree.json b/src/parser/test/flow/abstract_class/type.tree.json new file mode 100644 index 00000000000..0f05f8181b4 --- /dev/null +++ b/src/parser/test/flow/abstract_class/type.tree.json @@ -0,0 +1,84 @@ +{ + "type":"Program", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":55}}, + "range":[0,55], + "body":[ + { + "type":"ClassDeclaration", + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":55}}, + "range":[0,55], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":28}}, + "range":[6,28], + "name":"TypeParamNamedAbstract", + "typeAnnotation":null, + "optional":false + }, + "body":{ + "type":"ClassBody", + "loc":{"source":null,"start":{"line":1,"column":39},"end":{"line":1,"column":55}}, + "range":[39,55], + "body":[ + { + "type":"ClassProperty", + "loc":{"source":null,"start":{"line":1,"column":41},"end":{"line":1,"column":53}}, + "range":[41,53], + "key":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":41},"end":{"line":1,"column":42}}, + "range":[41,42], + "name":"x", + "typeAnnotation":null, + "optional":false + }, + "value":null, + "typeAnnotation":{ + "type":"TypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":42},"end":{"line":1,"column":52}}, + "range":[42,52], + "typeAnnotation":{ + "type":"GenericTypeAnnotation", + "loc":{"source":null,"start":{"line":1,"column":44},"end":{"line":1,"column":52}}, + "range":[44,52], + "id":{ + "type":"Identifier", + "loc":{"source":null,"start":{"line":1,"column":44},"end":{"line":1,"column":52}}, + "range":[44,52], + "name":"abstract", + "typeAnnotation":null, + "optional":false + }, + "typeParameters":null + } + }, + "computed":false, + "static":false, + "variance":null + } + ] + }, + "superClass":null, + "typeParameters":{ + "type":"TypeParameterDeclaration", + "loc":{"source":null,"start":{"line":1,"column":28},"end":{"line":1,"column":38}}, + "range":[28,38], + "params":[ + { + "type":"TypeParameter", + "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":37}}, + "range":[29,37], + "name":"abstract", + "bound":null, + "variance":null, + "default":null + } + ] + }, + "superTypeParameters":null, + "implements":[], + "decorators":[] + } + ], + "comments":[] +} diff --git a/src/parser/test/flow/async_await/migrated_0011.tree.json b/src/parser/test/flow/async_await/migrated_0011.tree.json index e0f8d7a53b4..eb43ade99a3 100644 --- a/src/parser/test/flow/async_await/migrated_0011.tree.json +++ b/src/parser/test/flow/async_await/migrated_0011.tree.json @@ -27,6 +27,8 @@ "loc":{"source":null,"start":{"line":1,"column":26},"end":{"line":1,"column":32}}, "range":[26,32], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":31},"end":{"line":1,"column":32}}, diff --git a/src/parser/test/flow/async_await/migrated_0012.tree.json b/src/parser/test/flow/async_await/migrated_0012.tree.json index abce9dbf8fe..74e2952fe2f 100644 --- a/src/parser/test/flow/async_await/migrated_0012.tree.json +++ b/src/parser/test/flow/async_await/migrated_0012.tree.json @@ -56,6 +56,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":46},"end":{"line":1,"column":51}}, diff --git a/src/parser/test/flow/async_await/migrated_0013.tree.json b/src/parser/test/flow/async_await/migrated_0013.tree.json index a5fdb37b6ea..5f13f656c4b 100644 --- a/src/parser/test/flow/async_await/migrated_0013.tree.json +++ b/src/parser/test/flow/async_await/migrated_0013.tree.json @@ -56,6 +56,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":46},"end":{"line":1,"column":51}}, diff --git a/src/parser/test/flow/async_await/migrated_0014.tree.json b/src/parser/test/flow/async_await/migrated_0014.tree.json index 4736673b059..3b786e04dc4 100644 --- a/src/parser/test/flow/async_await/migrated_0014.tree.json +++ b/src/parser/test/flow/async_await/migrated_0014.tree.json @@ -21,6 +21,8 @@ "loc":{"source":null,"start":{"line":1,"column":20},"end":{"line":1,"column":39}}, "range":[20,39], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":25},"end":{"line":1,"column":39}}, diff --git a/src/parser/test/flow/async_await/migrated_0015.tree.json b/src/parser/test/flow/async_await/migrated_0015.tree.json index 1e4d88ba9cd..8d17bfa53f6 100644 --- a/src/parser/test/flow/async_await/migrated_0015.tree.json +++ b/src/parser/test/flow/async_await/migrated_0015.tree.json @@ -21,6 +21,8 @@ "loc":{"source":null,"start":{"line":1,"column":20},"end":{"line":1,"column":39}}, "range":[20,39], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":25},"end":{"line":1,"column":39}}, diff --git a/src/parser/test/flow/async_await/migrated_0016.tree.json b/src/parser/test/flow/async_await/migrated_0016.tree.json index 17df84199b2..40166537023 100644 --- a/src/parser/test/flow/async_await/migrated_0016.tree.json +++ b/src/parser/test/flow/async_await/migrated_0016.tree.json @@ -21,6 +21,8 @@ "loc":{"source":null,"start":{"line":1,"column":22},"end":{"line":1,"column":30}}, "range":[22,30], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":27},"end":{"line":1,"column":30}}, diff --git a/src/parser/test/flow/call_properties/migrated_0000.tree.json b/src/parser/test/flow/call_properties/migrated_0000.tree.json index 5a556ab2c01..020a55dce9b 100644 --- a/src/parser/test/flow/call_properties/migrated_0000.tree.json +++ b/src/parser/test/flow/call_properties/migrated_0000.tree.json @@ -38,6 +38,8 @@ "loc":{"source":null,"start":{"line":1,"column":10},"end":{"line":1,"column":20}}, "range":[10,20], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":20}}, diff --git a/src/parser/test/flow/call_properties/migrated_0001.tree.json b/src/parser/test/flow/call_properties/migrated_0001.tree.json index 45785b98543..2752f81deca 100644 --- a/src/parser/test/flow/call_properties/migrated_0001.tree.json +++ b/src/parser/test/flow/call_properties/migrated_0001.tree.json @@ -38,6 +38,8 @@ "loc":{"source":null,"start":{"line":1,"column":10},"end":{"line":1,"column":20}}, "range":[10,20], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":20}}, diff --git a/src/parser/test/flow/call_properties/migrated_0002.tree.json b/src/parser/test/flow/call_properties/migrated_0002.tree.json index 6859eb7cd76..24f501de660 100644 --- a/src/parser/test/flow/call_properties/migrated_0002.tree.json +++ b/src/parser/test/flow/call_properties/migrated_0002.tree.json @@ -46,6 +46,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" @@ -62,6 +63,8 @@ "loc":{"source":null,"start":{"line":1,"column":10},"end":{"line":1,"column":20}}, "range":[10,20], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":20}}, @@ -101,6 +104,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"StringTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":46},"end":{"line":1,"column":52}}, diff --git a/src/parser/test/flow/call_properties/migrated_0003.tree.json b/src/parser/test/flow/call_properties/migrated_0003.tree.json index 05b43571c24..435c9704f9e 100644 --- a/src/parser/test/flow/call_properties/migrated_0003.tree.json +++ b/src/parser/test/flow/call_properties/migrated_0003.tree.json @@ -67,6 +67,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":27}}, diff --git a/src/parser/test/flow/call_properties/migrated_0004.tree.json b/src/parser/test/flow/call_properties/migrated_0004.tree.json index cacaf113721..936c9367f1a 100644 --- a/src/parser/test/flow/call_properties/migrated_0004.tree.json +++ b/src/parser/test/flow/call_properties/migrated_0004.tree.json @@ -33,6 +33,8 @@ "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":24}}, "range":[14,24], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":18},"end":{"line":1,"column":24}}, diff --git a/src/parser/test/flow/call_properties_invalid/migrated_0000.tree.json b/src/parser/test/flow/call_properties_invalid/migrated_0000.tree.json index 72cbb59118e..5fa42c795c7 100644 --- a/src/parser/test/flow/call_properties_invalid/migrated_0000.tree.json +++ b/src/parser/test/flow/call_properties_invalid/migrated_0000.tree.json @@ -48,6 +48,8 @@ "loc":{"source":null,"start":{"line":1,"column":10},"end":{"line":2,"column":0}}, "range":[10,15], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"AnyTypeAnnotation", "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":0}}, diff --git a/src/parser/test/flow/class_method_kinds/multiple_constructors.tree.json b/src/parser/test/flow/class_method_kinds/multiple_constructors.tree.json index f7f5aa2e231..6c073d0a6d5 100644 --- a/src/parser/test/flow/class_method_kinds/multiple_constructors.tree.json +++ b/src/parser/test/flow/class_method_kinds/multiple_constructors.tree.json @@ -6,7 +6,7 @@ }, { "loc":{"source":null,"start":{"line":7,"column":2},"end":{"line":7,"column":28}}, - "message":"Classes may not have fields named `constructor`." + "message":"Classes may not have static fields named `constructor`." }, { "loc":{"source":null,"start":{"line":11,"column":2},"end":{"line":11,"column":21}}, diff --git a/src/parser/test/flow/class_properties/migrated_0003.tree.json b/src/parser/test/flow/class_properties/migrated_0003.tree.json index 12fd7cc4ca2..fa1cb4d43fd 100644 --- a/src/parser/test/flow/class_properties/migrated_0003.tree.json +++ b/src/parser/test/flow/class_properties/migrated_0003.tree.json @@ -1,38 +1,12 @@ { - "errors":[ - { - "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":22}}, - "message":"Unexpected token =" - }, - { - "loc":{"source":null,"start":{"line":1,"column":23},"end":{"line":1,"column":31}}, - "message":"Unexpected string" - }, - { - "loc":{"source":null,"start":{"line":1,"column":31},"end":{"line":1,"column":32}}, - "message":"Unexpected token ;" - }, - { - "loc":{"source":null,"start":{"line":1,"column":33},"end":{"line":1,"column":34}}, - "message":"Unexpected token }" - }, - { - "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":0}}, - "message":"Rest parameter must be final parameter of an argument list" - }, - { - "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":0}}, - "message":"Unexpected end of input" - } - ], "type":"Program", - "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":2,"column":0}}, - "range":[0,35], + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":34}}, + "range":[0,34], "body":[ { "type":"ClassDeclaration", - "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":2,"column":0}}, - "range":[0,35], + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":34}}, + "range":[0,34], "id":{ "type":"Identifier", "loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":16}}, @@ -43,8 +17,8 @@ }, "body":{ "type":"ClassBody", - "loc":{"source":null,"start":{"line":1,"column":17},"end":{"line":2,"column":0}}, - "range":[17,35], + "loc":{"source":null,"start":{"line":1,"column":17},"end":{"line":1,"column":34}}, + "range":[17,34], "body":[ { "type":"ClassProperty", @@ -63,51 +37,6 @@ "computed":false, "static":false, "variance":null - }, - { - "type":"MethodDefinition", - "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":2,"column":0}}, - "range":[21,35], - "key":{ - "type":"Identifier", - "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":22}}, - "range":[21,22], - "name":"", - "typeAnnotation":null, - "optional":false - }, - "value":{ - "type":"FunctionExpression", - "loc":{"source":null,"start":{"line":1,"column":23},"end":{"line":2,"column":0}}, - "range":[23,35], - "id":null, - "params":[ - { - "type":"Identifier", - "loc":{"source":null,"start":{"line":1,"column":31},"end":{"line":1,"column":32}}, - "range":[31,32], - "name":"", - "typeAnnotation":null, - "optional":false - } - ], - "body":{ - "type":"BlockStatement", - "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":0}}, - "range":[35,35], - "body":[] - }, - "async":false, - "generator":false, - "predicate":null, - "expression":false, - "returnType":null, - "typeParameters":null - }, - "kind":"method", - "static":false, - "computed":false, - "decorators":[] } ] }, @@ -118,5 +47,15 @@ "decorators":[] } ], - "comments":[] + "comments":[], + "errors":[ + { + "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":22}}, + "message":"Unexpected token =" + }, + { + "loc":{"source":null,"start":{"line":1,"column":23},"end":{"line":1,"column":31}}, + "message":"Unexpected string" + } + ] } diff --git a/src/parser/test/flow/class_properties/migrated_0008.tree.json b/src/parser/test/flow/class_properties/migrated_0008.tree.json index 4867ed9b99e..6694f2c8cf2 100644 --- a/src/parser/test/flow/class_properties/migrated_0008.tree.json +++ b/src/parser/test/flow/class_properties/migrated_0008.tree.json @@ -1,38 +1,12 @@ { - "errors":[ - { - "loc":{"source":null,"start":{"line":1,"column":28},"end":{"line":1,"column":29}}, - "message":"Unexpected token =" - }, - { - "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":38}}, - "message":"Unexpected string" - }, - { - "loc":{"source":null,"start":{"line":1,"column":38},"end":{"line":1,"column":39}}, - "message":"Unexpected token ;" - }, - { - "loc":{"source":null,"start":{"line":1,"column":40},"end":{"line":1,"column":41}}, - "message":"Unexpected token }" - }, - { - "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":0}}, - "message":"Rest parameter must be final parameter of an argument list" - }, - { - "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":0}}, - "message":"Unexpected end of input" - } - ], "type":"Program", - "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":2,"column":0}}, - "range":[0,42], + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":41}}, + "range":[0,41], "body":[ { "type":"ClassDeclaration", - "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":2,"column":0}}, - "range":[0,42], + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":1,"column":41}}, + "range":[0,41], "id":{ "type":"Identifier", "loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":16}}, @@ -43,8 +17,8 @@ }, "body":{ "type":"ClassBody", - "loc":{"source":null,"start":{"line":1,"column":17},"end":{"line":2,"column":0}}, - "range":[17,42], + "loc":{"source":null,"start":{"line":1,"column":17},"end":{"line":1,"column":41}}, + "range":[17,41], "body":[ { "type":"ClassProperty", @@ -63,51 +37,6 @@ "computed":false, "static":true, "variance":null - }, - { - "type":"MethodDefinition", - "loc":{"source":null,"start":{"line":1,"column":28},"end":{"line":2,"column":0}}, - "range":[28,42], - "key":{ - "type":"Identifier", - "loc":{"source":null,"start":{"line":1,"column":28},"end":{"line":1,"column":29}}, - "range":[28,29], - "name":"", - "typeAnnotation":null, - "optional":false - }, - "value":{ - "type":"FunctionExpression", - "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":2,"column":0}}, - "range":[30,42], - "id":null, - "params":[ - { - "type":"Identifier", - "loc":{"source":null,"start":{"line":1,"column":38},"end":{"line":1,"column":39}}, - "range":[38,39], - "name":"", - "typeAnnotation":null, - "optional":false - } - ], - "body":{ - "type":"BlockStatement", - "loc":{"source":null,"start":{"line":2,"column":0},"end":{"line":2,"column":0}}, - "range":[42,42], - "body":[] - }, - "async":false, - "generator":false, - "predicate":null, - "expression":false, - "returnType":null, - "typeParameters":null - }, - "kind":"method", - "static":false, - "computed":false, - "decorators":[] } ] }, @@ -118,5 +47,15 @@ "decorators":[] } ], - "comments":[] + "comments":[], + "errors":[ + { + "loc":{"source":null,"start":{"line":1,"column":28},"end":{"line":1,"column":29}}, + "message":"Unexpected token =" + }, + { + "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":38}}, + "message":"Unexpected string" + } + ] } diff --git a/src/parser/test/flow/class_properties/migrated_0025.tree.json b/src/parser/test/flow/class_properties/migrated_0025.tree.json index ba4af9ab403..ffff3cdd556 100644 --- a/src/parser/test/flow/class_properties/migrated_0025.tree.json +++ b/src/parser/test/flow/class_properties/migrated_0025.tree.json @@ -1,34 +1,12 @@ { - "errors":[ - { - "loc":{"source":null,"start":{"line":3,"column":12},"end":{"line":3,"column":13}}, - "message":"Unexpected token :" - }, - { - "loc":{"source":null,"start":{"line":3,"column":14},"end":{"line":3,"column":20}}, - "message":"Unexpected identifier" - }, - { - "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":1}}, - "message":"Unexpected token }" - }, - { - "loc":{"source":null,"start":{"line":5,"column":0},"end":{"line":5,"column":0}}, - "message":"Unexpected end of input" - }, - { - "loc":{"source":null,"start":{"line":5,"column":0},"end":{"line":5,"column":0}}, - "message":"Rest parameter must be final parameter of an argument list" - } - ], "type":"Program", - "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":5,"column":0}}, - "range":[0,43], + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, + "range":[0,42], "body":[ { "type":"ClassDeclaration", - "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":5,"column":0}}, - "range":[0,43], + "loc":{"source":null,"start":{"line":1,"column":0},"end":{"line":4,"column":1}}, + "range":[0,42], "id":{ "type":"Identifier", "loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":7}}, @@ -39,8 +17,8 @@ }, "body":{ "type":"ClassBody", - "loc":{"source":null,"start":{"line":1,"column":8},"end":{"line":5,"column":0}}, - "range":[8,43], + "loc":{"source":null,"start":{"line":1,"column":8},"end":{"line":4,"column":1}}, + "range":[8,42], "body":[ { "type":"ClassProperty", @@ -79,51 +57,6 @@ "computed":false, "static":false, "variance":null - }, - { - "type":"MethodDefinition", - "loc":{"source":null,"start":{"line":3,"column":12},"end":{"line":5,"column":0}}, - "range":[32,43], - "key":{ - "type":"Identifier", - "loc":{"source":null,"start":{"line":3,"column":12},"end":{"line":3,"column":13}}, - "range":[32,33], - "name":"", - "typeAnnotation":null, - "optional":false - }, - "value":{ - "type":"FunctionExpression", - "loc":{"source":null,"start":{"line":3,"column":14},"end":{"line":5,"column":0}}, - "range":[34,43], - "id":null, - "params":[ - { - "type":"Identifier", - "loc":{"source":null,"start":{"line":4,"column":0},"end":{"line":4,"column":1}}, - "range":[41,42], - "name":"", - "typeAnnotation":null, - "optional":false - } - ], - "body":{ - "type":"BlockStatement", - "loc":{"source":null,"start":{"line":5,"column":0},"end":{"line":5,"column":0}}, - "range":[43,43], - "body":[] - }, - "async":false, - "generator":false, - "predicate":null, - "expression":false, - "returnType":null, - "typeParameters":null - }, - "kind":"method", - "static":false, - "computed":false, - "decorators":[] } ] }, @@ -134,5 +67,15 @@ "decorators":[] } ], - "comments":[] + "comments":[], + "errors":[ + { + "loc":{"source":null,"start":{"line":3,"column":12},"end":{"line":3,"column":13}}, + "message":"Unexpected token :" + }, + { + "loc":{"source":null,"start":{"line":3,"column":14},"end":{"line":3,"column":20}}, + "message":"Unexpected identifier" + } + ] } diff --git a/src/parser/test/flow/private_class_properties/constructor.tree.json b/src/parser/test/flow/private_class_properties/constructor.tree.json index 85d1b00c853..3a927776736 100644 --- a/src/parser/test/flow/private_class_properties/constructor.tree.json +++ b/src/parser/test/flow/private_class_properties/constructor.tree.json @@ -7,6 +7,14 @@ { "loc":{"source":null,"start":{"line":6,"column":2},"end":{"line":6,"column":26}}, "message":"Classes may not have private methods." + }, + { + "loc":{"source":null,"start":{"line":10,"column":2},"end":{"line":10,"column":14}}, + "message":"Classes may not have fields named `#constructor`." + }, + { + "loc":{"source":null,"start":{"line":14,"column":9},"end":{"line":14,"column":21}}, + "message":"Classes may not have static fields named `#constructor`." } ], "type":"Program", diff --git a/src/parser/test/flow/private_class_properties/nested.tree.json b/src/parser/test/flow/private_class_properties/nested.tree.json index ab7ccec9cba..38e7e81e738 100644 --- a/src/parser/test/flow/private_class_properties/nested.tree.json +++ b/src/parser/test/flow/private_class_properties/nested.tree.json @@ -68,6 +68,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/private_class_properties/object_type.tree.json b/src/parser/test/flow/private_class_properties/object_type.tree.json index 9b6285c33ee..a8154d7d1ec 100644 --- a/src/parser/test/flow/private_class_properties/object_type.tree.json +++ b/src/parser/test/flow/private_class_properties/object_type.tree.json @@ -47,6 +47,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/aliases/migrated_0004.tree.json b/src/parser/test/flow/types/aliases/migrated_0004.tree.json index f32e462c546..aae1f47c091 100644 --- a/src/parser/test/flow/types/aliases/migrated_0004.tree.json +++ b/src/parser/test/flow/types/aliases/migrated_0004.tree.json @@ -46,6 +46,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":35},"end":{"line":1,"column":41}}, @@ -79,6 +81,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"StringTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":61},"end":{"line":1,"column":67}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0006.tree.json b/src/parser/test/flow/types/annotations/migrated_0006.tree.json index e5082db8bbd..74b40f6d78f 100644 --- a/src/parser/test/flow/types/annotations/migrated_0006.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0006.tree.json @@ -30,6 +30,8 @@ "loc":{"source":null,"start":{"line":1,"column":23},"end":{"line":1,"column":33}}, "range":[23,33], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":33}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0007.tree.json b/src/parser/test/flow/types/annotations/migrated_0007.tree.json index ddb2f19a9ba..66091047d15 100644 --- a/src/parser/test/flow/types/annotations/migrated_0007.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0007.tree.json @@ -30,6 +30,8 @@ "loc":{"source":null,"start":{"line":1,"column":23},"end":{"line":1,"column":35}}, "range":[23,35], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":35}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0008.tree.json b/src/parser/test/flow/types/annotations/migrated_0008.tree.json index ef38ded8c62..88dce8aeaf1 100644 --- a/src/parser/test/flow/types/annotations/migrated_0008.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0008.tree.json @@ -50,6 +50,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":35},"end":{"line":1,"column":41}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0009.tree.json b/src/parser/test/flow/types/annotations/migrated_0009.tree.json index 727e1da13a8..af9d5d36a24 100644 --- a/src/parser/test/flow/types/annotations/migrated_0009.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0009.tree.json @@ -69,6 +69,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":47},"end":{"line":1,"column":53}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0011.tree.json b/src/parser/test/flow/types/annotations/migrated_0011.tree.json index 61a31c900b9..f9143bedaf0 100644 --- a/src/parser/test/flow/types/annotations/migrated_0011.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0011.tree.json @@ -35,6 +35,8 @@ "loc":{"source":null,"start":{"line":1,"column":15},"end":{"line":1,"column":25}}, "range":[15,25], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":25}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0012.tree.json b/src/parser/test/flow/types/annotations/migrated_0012.tree.json index 6bc10c5fe70..6e0de723afc 100644 --- a/src/parser/test/flow/types/annotations/migrated_0012.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0012.tree.json @@ -55,6 +55,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":27},"end":{"line":1,"column":33}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0021.tree.json b/src/parser/test/flow/types/annotations/migrated_0021.tree.json index ca1988b8fc5..b77eaad3aa4 100644 --- a/src/parser/test/flow/types/annotations/migrated_0021.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0021.tree.json @@ -50,6 +50,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/migrated_0022.tree.json b/src/parser/test/flow/types/annotations/migrated_0022.tree.json index 4ed331b9613..9efe0c9a054 100644 --- a/src/parser/test/flow/types/annotations/migrated_0022.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0022.tree.json @@ -46,6 +46,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/migrated_0023.tree.json b/src/parser/test/flow/types/annotations/migrated_0023.tree.json index 00eeb054bfd..885c321c0e3 100644 --- a/src/parser/test/flow/types/annotations/migrated_0023.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0023.tree.json @@ -46,6 +46,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/migrated_0025.tree.json b/src/parser/test/flow/types/annotations/migrated_0025.tree.json index b1fc1a8c641..947d0aaaccb 100644 --- a/src/parser/test/flow/types/annotations/migrated_0025.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0025.tree.json @@ -64,6 +64,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" @@ -74,6 +75,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/migrated_0026.tree.json b/src/parser/test/flow/types/annotations/migrated_0026.tree.json index 770903ef255..5aefc5ad3c3 100644 --- a/src/parser/test/flow/types/annotations/migrated_0026.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0026.tree.json @@ -46,6 +46,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" @@ -69,6 +70,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/migrated_0027.tree.json b/src/parser/test/flow/types/annotations/migrated_0027.tree.json index f8ae6bb2572..363dff736cb 100644 --- a/src/parser/test/flow/types/annotations/migrated_0027.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0027.tree.json @@ -46,6 +46,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" @@ -69,6 +70,7 @@ }, "method":false, "optional":true, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/migrated_0030.tree.json b/src/parser/test/flow/types/annotations/migrated_0030.tree.json index c9e393946f5..277f6cefd57 100644 --- a/src/parser/test/flow/types/annotations/migrated_0030.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0030.tree.json @@ -44,6 +44,8 @@ "loc":{"source":null,"start":{"line":1,"column":9},"end":{"line":1,"column":43}}, "range":[9,43], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":37},"end":{"line":1,"column":43}}, @@ -92,6 +94,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/migrated_0031.tree.json b/src/parser/test/flow/types/annotations/migrated_0031.tree.json index 380f3b11be3..70b2086740d 100644 --- a/src/parser/test/flow/types/annotations/migrated_0031.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0031.tree.json @@ -44,6 +44,8 @@ "loc":{"source":null,"start":{"line":1,"column":9},"end":{"line":1,"column":26}}, "range":[9,26], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":20},"end":{"line":1,"column":26}}, @@ -54,6 +56,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"get" diff --git a/src/parser/test/flow/types/annotations/migrated_0032.tree.json b/src/parser/test/flow/types/annotations/migrated_0032.tree.json index a909e61cb89..536333d0d99 100644 --- a/src/parser/test/flow/types/annotations/migrated_0032.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0032.tree.json @@ -64,6 +64,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":33}}, @@ -74,6 +76,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"set" diff --git a/src/parser/test/flow/types/annotations/migrated_0033.tree.json b/src/parser/test/flow/types/annotations/migrated_0033.tree.json index 025ee5c0af7..03a484a6056 100644 --- a/src/parser/test/flow/types/annotations/migrated_0033.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0033.tree.json @@ -44,6 +44,8 @@ "loc":{"source":null,"start":{"line":1,"column":9},"end":{"line":1,"column":26}}, "range":[9,26], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":20},"end":{"line":1,"column":26}}, @@ -54,6 +56,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"get" @@ -95,6 +98,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":48},"end":{"line":1,"column":52}}, @@ -105,6 +110,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"set" diff --git a/src/parser/test/flow/types/annotations/migrated_0034.tree.json b/src/parser/test/flow/types/annotations/migrated_0034.tree.json index 79114b588c9..89a2b5e48b2 100644 --- a/src/parser/test/flow/types/annotations/migrated_0034.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0034.tree.json @@ -46,6 +46,7 @@ }, "method":false, "optional":true, + "abstract":false, "static":false, "variance":null, "kind":"init" @@ -69,6 +70,7 @@ }, "method":false, "optional":true, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/migrated_0035.tree.json b/src/parser/test/flow/types/annotations/migrated_0035.tree.json index 43a187cfe8b..7bf0f8bc2b6 100644 --- a/src/parser/test/flow/types/annotations/migrated_0035.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0035.tree.json @@ -70,6 +70,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":35}}, @@ -80,6 +82,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"get" diff --git a/src/parser/test/flow/types/annotations/migrated_0036.tree.json b/src/parser/test/flow/types/annotations/migrated_0036.tree.json index a948b3220a9..561b103be7d 100644 --- a/src/parser/test/flow/types/annotations/migrated_0036.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0036.tree.json @@ -50,6 +50,8 @@ "loc":{"source":null,"start":{"line":1,"column":9},"end":{"line":1,"column":24}}, "range":[9,24], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":20},"end":{"line":1,"column":24}}, @@ -60,6 +62,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"set" diff --git a/src/parser/test/flow/types/annotations/migrated_0037.tree.json b/src/parser/test/flow/types/annotations/migrated_0037.tree.json index a9f30580d39..31c493a10fc 100644 --- a/src/parser/test/flow/types/annotations/migrated_0037.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0037.tree.json @@ -50,6 +50,8 @@ "loc":{"source":null,"start":{"line":1,"column":9},"end":{"line":1,"column":27}}, "range":[9,27], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":27}}, @@ -60,6 +62,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"get" diff --git a/src/parser/test/flow/types/annotations/migrated_0038.tree.json b/src/parser/test/flow/types/annotations/migrated_0038.tree.json index 1df87180588..c4d9d5a6668 100644 --- a/src/parser/test/flow/types/annotations/migrated_0038.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0038.tree.json @@ -70,6 +70,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":34}}, @@ -80,6 +82,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"set" diff --git a/src/parser/test/flow/types/annotations/migrated_0039.tree.json b/src/parser/test/flow/types/annotations/migrated_0039.tree.json index 406000eb145..259f20da620 100644 --- a/src/parser/test/flow/types/annotations/migrated_0039.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0039.tree.json @@ -26,6 +26,8 @@ "loc":{"source":null,"start":{"line":1,"column":6},"end":{"line":1,"column":39}}, "range":[6,39], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":33},"end":{"line":1,"column":39}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0040.tree.json b/src/parser/test/flow/types/annotations/migrated_0040.tree.json index 92a24577d0e..94608e63ce9 100644 --- a/src/parser/test/flow/types/annotations/migrated_0040.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0040.tree.json @@ -65,6 +65,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"StringTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":34},"end":{"line":1,"column":40}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0058.tree.json b/src/parser/test/flow/types/annotations/migrated_0058.tree.json index 03d41714a3b..e1f9268387f 100644 --- a/src/parser/test/flow/types/annotations/migrated_0058.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0058.tree.json @@ -72,6 +72,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/migrated_0060.tree.json b/src/parser/test/flow/types/annotations/migrated_0060.tree.json index a09084b7ac7..b083ab725ea 100644 --- a/src/parser/test/flow/types/annotations/migrated_0060.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0060.tree.json @@ -76,6 +76,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/migrated_0063.tree.json b/src/parser/test/flow/types/annotations/migrated_0063.tree.json index f967ba5e812..3a84670c958 100644 --- a/src/parser/test/flow/types/annotations/migrated_0063.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0063.tree.json @@ -54,6 +54,8 @@ "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":68}}, "range":[21,68], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":60},"end":{"line":1,"column":68}}, @@ -181,6 +183,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/migrated_0064.tree.json b/src/parser/test/flow/types/annotations/migrated_0064.tree.json index 75e650dd919..8530ef2f749 100644 --- a/src/parser/test/flow/types/annotations/migrated_0064.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0064.tree.json @@ -26,6 +26,8 @@ "loc":{"source":null,"start":{"line":1,"column":8},"end":{"line":1,"column":35}}, "range":[8,35], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"UnionTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":35}}, @@ -41,6 +43,8 @@ "loc":{"source":null,"start":{"line":1,"column":23},"end":{"line":1,"column":35}}, "range":[23,35], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"StringTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":35}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0068.tree.json b/src/parser/test/flow/types/annotations/migrated_0068.tree.json index e0090b8300d..0a19a9759bc 100644 --- a/src/parser/test/flow/types/annotations/migrated_0068.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0068.tree.json @@ -54,6 +54,8 @@ "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":68}}, "range":[21,68], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":60},"end":{"line":1,"column":68}}, @@ -181,6 +183,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/migrated_0069.tree.json b/src/parser/test/flow/types/annotations/migrated_0069.tree.json index 86a0c0a2dc2..df6b0b7fa55 100644 --- a/src/parser/test/flow/types/annotations/migrated_0069.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0069.tree.json @@ -26,6 +26,8 @@ "loc":{"source":null,"start":{"line":1,"column":8},"end":{"line":1,"column":35}}, "range":[8,35], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"IntersectionTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":35}}, @@ -41,6 +43,8 @@ "loc":{"source":null,"start":{"line":1,"column":23},"end":{"line":1,"column":35}}, "range":[23,35], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"StringTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":35}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0071.tree.json b/src/parser/test/flow/types/annotations/migrated_0071.tree.json index 1a97ae1dd64..82c485c09bb 100644 --- a/src/parser/test/flow/types/annotations/migrated_0071.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0071.tree.json @@ -55,6 +55,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":27},"end":{"line":1,"column":28}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0072.tree.json b/src/parser/test/flow/types/annotations/migrated_0072.tree.json index 339b792df4e..730e7e70e13 100644 --- a/src/parser/test/flow/types/annotations/migrated_0072.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0072.tree.json @@ -103,6 +103,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"AnyTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":58},"end":{"line":1,"column":61}}, diff --git a/src/parser/test/flow/types/annotations/migrated_0079.tree.json b/src/parser/test/flow/types/annotations/migrated_0079.tree.json index e404a4fa4a9..29556d5830f 100644 --- a/src/parser/test/flow/types/annotations/migrated_0079.tree.json +++ b/src/parser/test/flow/types/annotations/migrated_0079.tree.json @@ -53,6 +53,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations/static_is_reserved_param.tree.json b/src/parser/test/flow/types/annotations/static_is_reserved_param.tree.json index eeb0ad1030a..779a7ae7e0d 100644 --- a/src/parser/test/flow/types/annotations/static_is_reserved_param.tree.json +++ b/src/parser/test/flow/types/annotations/static_is_reserved_param.tree.json @@ -47,6 +47,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":33}}, diff --git a/src/parser/test/flow/types/annotations/void_is_reserved_param.tree.json b/src/parser/test/flow/types/annotations/void_is_reserved_param.tree.json index 51d8e8bb79c..749cb31df2f 100644 --- a/src/parser/test/flow/types/annotations/void_is_reserved_param.tree.json +++ b/src/parser/test/flow/types/annotations/void_is_reserved_param.tree.json @@ -47,6 +47,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":27},"end":{"line":1,"column":31}}, diff --git a/src/parser/test/flow/types/annotations_in_comments/migrated_0006.tree.json b/src/parser/test/flow/types/annotations_in_comments/migrated_0006.tree.json index 304c8f8e7cc..94470ef881f 100644 --- a/src/parser/test/flow/types/annotations_in_comments/migrated_0006.tree.json +++ b/src/parser/test/flow/types/annotations_in_comments/migrated_0006.tree.json @@ -30,6 +30,8 @@ "loc":{"source":null,"start":{"line":1,"column":39},"end":{"line":1,"column":49}}, "range":[39,49], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":45},"end":{"line":1,"column":49}}, diff --git a/src/parser/test/flow/types/annotations_in_comments/migrated_0007.tree.json b/src/parser/test/flow/types/annotations_in_comments/migrated_0007.tree.json index 26deed61f25..0e56a90579f 100644 --- a/src/parser/test/flow/types/annotations_in_comments/migrated_0007.tree.json +++ b/src/parser/test/flow/types/annotations_in_comments/migrated_0007.tree.json @@ -30,6 +30,8 @@ "loc":{"source":null,"start":{"line":1,"column":25},"end":{"line":1,"column":37}}, "range":[25,37], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":31},"end":{"line":1,"column":37}}, diff --git a/src/parser/test/flow/types/annotations_in_comments/migrated_0008.tree.json b/src/parser/test/flow/types/annotations_in_comments/migrated_0008.tree.json index ddedf061a69..a746be2f9a0 100644 --- a/src/parser/test/flow/types/annotations_in_comments/migrated_0008.tree.json +++ b/src/parser/test/flow/types/annotations_in_comments/migrated_0008.tree.json @@ -50,6 +50,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":37},"end":{"line":1,"column":43}}, diff --git a/src/parser/test/flow/types/annotations_in_comments/migrated_0009.tree.json b/src/parser/test/flow/types/annotations_in_comments/migrated_0009.tree.json index e140190c4a2..6ca55bb4557 100644 --- a/src/parser/test/flow/types/annotations_in_comments/migrated_0009.tree.json +++ b/src/parser/test/flow/types/annotations_in_comments/migrated_0009.tree.json @@ -69,6 +69,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":49},"end":{"line":1,"column":55}}, diff --git a/src/parser/test/flow/types/annotations_in_comments/migrated_0011.tree.json b/src/parser/test/flow/types/annotations_in_comments/migrated_0011.tree.json index f484fda4833..07365fe07f4 100644 --- a/src/parser/test/flow/types/annotations_in_comments/migrated_0011.tree.json +++ b/src/parser/test/flow/types/annotations_in_comments/migrated_0011.tree.json @@ -35,6 +35,8 @@ "loc":{"source":null,"start":{"line":1,"column":17},"end":{"line":1,"column":27}}, "range":[17,27], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":23},"end":{"line":1,"column":27}}, diff --git a/src/parser/test/flow/types/annotations_in_comments/migrated_0012.tree.json b/src/parser/test/flow/types/annotations_in_comments/migrated_0012.tree.json index dc2fad35bc1..9385951e4cd 100644 --- a/src/parser/test/flow/types/annotations_in_comments/migrated_0012.tree.json +++ b/src/parser/test/flow/types/annotations_in_comments/migrated_0012.tree.json @@ -39,6 +39,8 @@ "loc":{"source":null,"start":{"line":3,"column":2},"end":{"line":3,"column":17}}, "range":[21,36], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"StringTypeAnnotation", "loc":{"source":null,"start":{"line":3,"column":11},"end":{"line":3,"column":17}}, @@ -49,6 +51,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/annotations_in_comments/migrated_0013.tree.json b/src/parser/test/flow/types/annotations_in_comments/migrated_0013.tree.json index 5777d5d02b9..d51b0aed295 100644 --- a/src/parser/test/flow/types/annotations_in_comments/migrated_0013.tree.json +++ b/src/parser/test/flow/types/annotations_in_comments/migrated_0013.tree.json @@ -39,6 +39,8 @@ "loc":{"source":null,"start":{"line":3,"column":2},"end":{"line":3,"column":17}}, "range":[31,46], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"StringTypeAnnotation", "loc":{"source":null,"start":{"line":3,"column":11},"end":{"line":3,"column":17}}, @@ -49,6 +51,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_class/method_with_this_return.tree.json b/src/parser/test/flow/types/declare_class/method_with_this_return.tree.json index 7c7805509a2..0453430b3b1 100644 --- a/src/parser/test/flow/types/declare_class/method_with_this_return.tree.json +++ b/src/parser/test/flow/types/declare_class/method_with_this_return.tree.json @@ -39,6 +39,8 @@ "loc":{"source":null,"start":{"line":2,"column":2},"end":{"line":2,"column":11}}, "range":[22,31], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":2,"column":7},"end":{"line":2,"column":11}}, @@ -58,6 +60,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_class/multiple_extends.tree.json b/src/parser/test/flow/types/declare_class/multiple_extends.tree.json index 73942a369c6..f4324ff7fb1 100644 --- a/src/parser/test/flow/types/declare_class/multiple_extends.tree.json +++ b/src/parser/test/flow/types/declare_class/multiple_extends.tree.json @@ -7,10 +7,6 @@ { "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":30}}, "message":"Unexpected token {" - }, - { - "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":31}}, - "message":"Unexpected token }" } ], "type":"Program", @@ -35,31 +31,7 @@ "loc":{"source":null,"start":{"line":1,"column":25},"end":{"line":1,"column":31}}, "range":[25,31], "exact":false, - "properties":[ - { - "type":"ObjectTypeProperty", - "loc":{"source":null,"start":{"line":1,"column":27},"end":{"line":1,"column":31}}, - "range":[27,31], - "key":{ - "type":"Identifier", - "loc":{"source":null,"start":{"line":1,"column":27},"end":{"line":1,"column":28}}, - "range":[27,28], - "name":"C", - "typeAnnotation":null, - "optional":false - }, - "value":{ - "type":"AnyTypeAnnotation", - "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":31}}, - "range":[30,31] - }, - "method":false, - "optional":false, - "static":false, - "variance":null, - "kind":"init" - } - ], + "properties":[], "indexers":[], "callProperties":[] }, diff --git a/src/parser/test/flow/types/declare_export/class/migrated_0018.tree.json b/src/parser/test/flow/types/declare_export/class/migrated_0018.tree.json index ed9301284d4..0754a3e0ba4 100644 --- a/src/parser/test/flow/types/declare_export/class/migrated_0018.tree.json +++ b/src/parser/test/flow/types/declare_export/class/migrated_0018.tree.json @@ -61,6 +61,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_export/class/migrated_0019.tree.json b/src/parser/test/flow/types/declare_export/class/migrated_0019.tree.json index 797bcfcb1d0..ac88d6155ac 100644 --- a/src/parser/test/flow/types/declare_export/class/migrated_0019.tree.json +++ b/src/parser/test/flow/types/declare_export/class/migrated_0019.tree.json @@ -44,6 +44,8 @@ "loc":{"source":null,"start":{"line":1,"column":25},"end":{"line":1,"column":45}}, "range":[25,45], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":39},"end":{"line":1,"column":45}}, @@ -54,6 +56,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":true, "variance":null, "kind":"init" @@ -77,6 +80,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":true, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_export/class/migrated_0021.tree.json b/src/parser/test/flow/types/declare_export/class/migrated_0021.tree.json index 5711903ace9..30541fa377b 100644 --- a/src/parser/test/flow/types/declare_export/class/migrated_0021.tree.json +++ b/src/parser/test/flow/types/declare_export/class/migrated_0021.tree.json @@ -38,6 +38,8 @@ "loc":{"source":null,"start":{"line":1,"column":32},"end":{"line":1,"column":43}}, "range":[32,43], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":37},"end":{"line":1,"column":43}}, diff --git a/src/parser/test/flow/types/declare_export/declare_export_class_prop_named_static.tree.json b/src/parser/test/flow/types/declare_export/declare_export_class_prop_named_static.tree.json index 6faeb3c8074..713f6f58257 100644 --- a/src/parser/test/flow/types/declare_export/declare_export_class_prop_named_static.tree.json +++ b/src/parser/test/flow/types/declare_export/declare_export_class_prop_named_static.tree.json @@ -46,6 +46,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_export/default/migrated_0024.tree.json b/src/parser/test/flow/types/declare_export/default/migrated_0024.tree.json index ae64610fed8..7be0bc3be19 100644 --- a/src/parser/test/flow/types/declare_export/default/migrated_0024.tree.json +++ b/src/parser/test/flow/types/declare_export/default/migrated_0024.tree.json @@ -26,6 +26,8 @@ "loc":{"source":null,"start":{"line":1,"column":35},"end":{"line":1,"column":43}}, "range":[35,43], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":39},"end":{"line":1,"column":43}}, diff --git a/src/parser/test/flow/types/declare_export/default/migrated_0025.tree.json b/src/parser/test/flow/types/declare_export/default/migrated_0025.tree.json index a771da8b71e..9ddbc50cd5a 100644 --- a/src/parser/test/flow/types/declare_export/default/migrated_0025.tree.json +++ b/src/parser/test/flow/types/declare_export/default/migrated_0025.tree.json @@ -26,6 +26,8 @@ "loc":{"source":null,"start":{"line":1,"column":35},"end":{"line":1,"column":43}}, "range":[35,43], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":39},"end":{"line":1,"column":43}}, diff --git a/src/parser/test/flow/types/declare_export/default/migrated_0026.tree.json b/src/parser/test/flow/types/declare_export/default/migrated_0026.tree.json index aa28b51e8c4..bfa621b6ebe 100644 --- a/src/parser/test/flow/types/declare_export/default/migrated_0026.tree.json +++ b/src/parser/test/flow/types/declare_export/default/migrated_0026.tree.json @@ -26,6 +26,8 @@ "loc":{"source":null,"start":{"line":1,"column":35},"end":{"line":1,"column":46}}, "range":[35,46], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":42},"end":{"line":1,"column":46}}, diff --git a/src/parser/test/flow/types/declare_export/default/migrated_0027.tree.json b/src/parser/test/flow/types/declare_export/default/migrated_0027.tree.json index 74050a9bd66..aa3e8a45a78 100644 --- a/src/parser/test/flow/types/declare_export/default/migrated_0027.tree.json +++ b/src/parser/test/flow/types/declare_export/default/migrated_0027.tree.json @@ -65,6 +65,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":59},"end":{"line":1,"column":63}}, diff --git a/src/parser/test/flow/types/declare_export/default/migrated_0029.tree.json b/src/parser/test/flow/types/declare_export/default/migrated_0029.tree.json index bb76faf2724..6fca00a39e8 100644 --- a/src/parser/test/flow/types/declare_export/default/migrated_0029.tree.json +++ b/src/parser/test/flow/types/declare_export/default/migrated_0029.tree.json @@ -61,6 +61,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_export/default/migrated_0030.tree.json b/src/parser/test/flow/types/declare_export/default/migrated_0030.tree.json index d36da94ef47..63e9697ddeb 100644 --- a/src/parser/test/flow/types/declare_export/default/migrated_0030.tree.json +++ b/src/parser/test/flow/types/declare_export/default/migrated_0030.tree.json @@ -44,6 +44,8 @@ "loc":{"source":null,"start":{"line":1,"column":33},"end":{"line":1,"column":53}}, "range":[33,53], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":47},"end":{"line":1,"column":53}}, @@ -54,6 +56,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":true, "variance":null, "kind":"init" @@ -77,6 +80,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":true, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_export/default/migrated_0032.tree.json b/src/parser/test/flow/types/declare_export/default/migrated_0032.tree.json index e5b45cdfd69..a46021c3cd2 100644 --- a/src/parser/test/flow/types/declare_export/default/migrated_0032.tree.json +++ b/src/parser/test/flow/types/declare_export/default/migrated_0032.tree.json @@ -38,6 +38,8 @@ "loc":{"source":null,"start":{"line":1,"column":40},"end":{"line":1,"column":51}}, "range":[40,51], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":45},"end":{"line":1,"column":51}}, diff --git a/src/parser/test/flow/types/declare_export/function/migrated_0012.tree.json b/src/parser/test/flow/types/declare_export/function/migrated_0012.tree.json index d727e378702..1404702b217 100644 --- a/src/parser/test/flow/types/declare_export/function/migrated_0012.tree.json +++ b/src/parser/test/flow/types/declare_export/function/migrated_0012.tree.json @@ -26,6 +26,8 @@ "loc":{"source":null,"start":{"line":1,"column":27},"end":{"line":1,"column":35}}, "range":[27,35], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":31},"end":{"line":1,"column":35}}, diff --git a/src/parser/test/flow/types/declare_export/function/migrated_0013.tree.json b/src/parser/test/flow/types/declare_export/function/migrated_0013.tree.json index 05d0dc62755..da681f5051d 100644 --- a/src/parser/test/flow/types/declare_export/function/migrated_0013.tree.json +++ b/src/parser/test/flow/types/declare_export/function/migrated_0013.tree.json @@ -26,6 +26,8 @@ "loc":{"source":null,"start":{"line":1,"column":27},"end":{"line":1,"column":35}}, "range":[27,35], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":31},"end":{"line":1,"column":35}}, diff --git a/src/parser/test/flow/types/declare_export/function/migrated_0014.tree.json b/src/parser/test/flow/types/declare_export/function/migrated_0014.tree.json index ef28906a0ec..63e9b6516f3 100644 --- a/src/parser/test/flow/types/declare_export/function/migrated_0014.tree.json +++ b/src/parser/test/flow/types/declare_export/function/migrated_0014.tree.json @@ -26,6 +26,8 @@ "loc":{"source":null,"start":{"line":1,"column":27},"end":{"line":1,"column":38}}, "range":[27,38], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":34},"end":{"line":1,"column":38}}, diff --git a/src/parser/test/flow/types/declare_export/function/migrated_0015.tree.json b/src/parser/test/flow/types/declare_export/function/migrated_0015.tree.json index 924aba29d99..6229a3973fd 100644 --- a/src/parser/test/flow/types/declare_export/function/migrated_0015.tree.json +++ b/src/parser/test/flow/types/declare_export/function/migrated_0015.tree.json @@ -65,6 +65,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":51},"end":{"line":1,"column":55}}, diff --git a/src/parser/test/flow/types/declare_export/function/migrated_0016.tree.json b/src/parser/test/flow/types/declare_export/function/migrated_0016.tree.json index 61fed36dd12..d81de7a7d7f 100644 --- a/src/parser/test/flow/types/declare_export/function/migrated_0016.tree.json +++ b/src/parser/test/flow/types/declare_export/function/migrated_0016.tree.json @@ -58,6 +58,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":48},"end":{"line":1,"column":52}}, diff --git a/src/parser/test/flow/types/declare_export_invalid/migrated_0012.tree.json b/src/parser/test/flow/types/declare_export_invalid/migrated_0012.tree.json index 02e7cefd855..a21692f9ab5 100644 --- a/src/parser/test/flow/types/declare_export_invalid/migrated_0012.tree.json +++ b/src/parser/test/flow/types/declare_export_invalid/migrated_0012.tree.json @@ -36,6 +36,8 @@ "loc":{"source":null,"start":{"line":2,"column":27},"end":{"line":3,"column":0}}, "range":[61,65], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"AnyTypeAnnotation", "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":0}}, diff --git a/src/parser/test/flow/types/declare_export_invalid/migrated_0014.tree.json b/src/parser/test/flow/types/declare_export_invalid/migrated_0014.tree.json index 496064771e3..dabb198063c 100644 --- a/src/parser/test/flow/types/declare_export_invalid/migrated_0014.tree.json +++ b/src/parser/test/flow/types/declare_export_invalid/migrated_0014.tree.json @@ -46,6 +46,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":true, "variance":null, "kind":"init" @@ -69,6 +70,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_interface/migrated_0002.tree.json b/src/parser/test/flow/types/declare_interface/migrated_0002.tree.json index efca66340d6..7bbec1971ff 100644 --- a/src/parser/test/flow/types/declare_interface/migrated_0002.tree.json +++ b/src/parser/test/flow/types/declare_interface/migrated_0002.tree.json @@ -41,6 +41,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_interface/migrated_0010.tree.json b/src/parser/test/flow/types/declare_interface/migrated_0010.tree.json index 4db24b36ca6..420d7e1b59c 100644 --- a/src/parser/test/flow/types/declare_interface/migrated_0010.tree.json +++ b/src/parser/test/flow/types/declare_interface/migrated_0010.tree.json @@ -41,6 +41,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_module_with_exports/migrated_0004.tree.json b/src/parser/test/flow/types/declare_module_with_exports/migrated_0004.tree.json index 00e291ab76b..f12689c1ba3 100644 --- a/src/parser/test/flow/types/declare_module_with_exports/migrated_0004.tree.json +++ b/src/parser/test/flow/types/declare_module_with_exports/migrated_0004.tree.json @@ -62,6 +62,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"StringTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":64},"end":{"line":1,"column":70}}, diff --git a/src/parser/test/flow/types/declare_module_with_exports/migrated_0005.tree.json b/src/parser/test/flow/types/declare_module_with_exports/migrated_0005.tree.json index fb79b8e6646..3425f83935f 100644 --- a/src/parser/test/flow/types/declare_module_with_exports/migrated_0005.tree.json +++ b/src/parser/test/flow/types/declare_module_with_exports/migrated_0005.tree.json @@ -80,6 +80,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":68},"end":{"line":1,"column":72}}, @@ -90,6 +92,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_statements/declare_class_prop_named_static.tree.json b/src/parser/test/flow/types/declare_statements/declare_class_prop_named_static.tree.json index 22730f35620..4a663f93481 100644 --- a/src/parser/test/flow/types/declare_statements/declare_class_prop_named_static.tree.json +++ b/src/parser/test/flow/types/declare_statements/declare_class_prop_named_static.tree.json @@ -41,6 +41,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_statements/migrated_0002.tree.json b/src/parser/test/flow/types/declare_statements/migrated_0002.tree.json index e93122778aa..774dabf8919 100644 --- a/src/parser/test/flow/types/declare_statements/migrated_0002.tree.json +++ b/src/parser/test/flow/types/declare_statements/migrated_0002.tree.json @@ -21,6 +21,8 @@ "loc":{"source":null,"start":{"line":1,"column":20},"end":{"line":1,"column":28}}, "range":[20,28], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":24},"end":{"line":1,"column":28}}, diff --git a/src/parser/test/flow/types/declare_statements/migrated_0003.tree.json b/src/parser/test/flow/types/declare_statements/migrated_0003.tree.json index ade7c6fb4c7..0a0bf2b68ba 100644 --- a/src/parser/test/flow/types/declare_statements/migrated_0003.tree.json +++ b/src/parser/test/flow/types/declare_statements/migrated_0003.tree.json @@ -21,6 +21,8 @@ "loc":{"source":null,"start":{"line":1,"column":20},"end":{"line":1,"column":28}}, "range":[20,28], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":24},"end":{"line":1,"column":28}}, diff --git a/src/parser/test/flow/types/declare_statements/migrated_0004.tree.json b/src/parser/test/flow/types/declare_statements/migrated_0004.tree.json index 04f622ca7c4..91d67f79b03 100644 --- a/src/parser/test/flow/types/declare_statements/migrated_0004.tree.json +++ b/src/parser/test/flow/types/declare_statements/migrated_0004.tree.json @@ -60,6 +60,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":44},"end":{"line":1,"column":48}}, diff --git a/src/parser/test/flow/types/declare_statements/migrated_0005.tree.json b/src/parser/test/flow/types/declare_statements/migrated_0005.tree.json index 06ceaee2acd..1f9c6bc0b76 100644 --- a/src/parser/test/flow/types/declare_statements/migrated_0005.tree.json +++ b/src/parser/test/flow/types/declare_statements/migrated_0005.tree.json @@ -53,6 +53,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":2,"column":41},"end":{"line":2,"column":45}}, diff --git a/src/parser/test/flow/types/declare_statements/migrated_0007.tree.json b/src/parser/test/flow/types/declare_statements/migrated_0007.tree.json index 470c5e9bbaf..0d852ec7377 100644 --- a/src/parser/test/flow/types/declare_statements/migrated_0007.tree.json +++ b/src/parser/test/flow/types/declare_statements/migrated_0007.tree.json @@ -56,6 +56,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_statements/migrated_0008.tree.json b/src/parser/test/flow/types/declare_statements/migrated_0008.tree.json index f99bf912365..f1874bf436e 100644 --- a/src/parser/test/flow/types/declare_statements/migrated_0008.tree.json +++ b/src/parser/test/flow/types/declare_statements/migrated_0008.tree.json @@ -39,6 +39,8 @@ "loc":{"source":null,"start":{"line":1,"column":18},"end":{"line":1,"column":38}}, "range":[18,38], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":32},"end":{"line":1,"column":38}}, @@ -49,6 +51,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":true, "variance":null, "kind":"init" @@ -72,6 +75,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":true, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/declare_statements/migrated_0009.tree.json b/src/parser/test/flow/types/declare_statements/migrated_0009.tree.json index 0163c68b240..f25a6083ed4 100644 --- a/src/parser/test/flow/types/declare_statements/migrated_0009.tree.json +++ b/src/parser/test/flow/types/declare_statements/migrated_0009.tree.json @@ -33,6 +33,8 @@ "loc":{"source":null,"start":{"line":1,"column":25},"end":{"line":1,"column":36}}, "range":[25,36], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":36}}, diff --git a/src/parser/test/flow/types/declare_statements/migrated_0011.tree.json b/src/parser/test/flow/types/declare_statements/migrated_0011.tree.json index 6ee5c61dcdd..62b32142ce6 100644 --- a/src/parser/test/flow/types/declare_statements/migrated_0011.tree.json +++ b/src/parser/test/flow/types/declare_statements/migrated_0011.tree.json @@ -39,6 +39,8 @@ "loc":{"source":null,"start":{"line":1,"column":18},"end":{"line":1,"column":35}}, "range":[18,35], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":35}}, @@ -49,6 +51,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"get" diff --git a/src/parser/test/flow/types/declare_statements/migrated_0012.tree.json b/src/parser/test/flow/types/declare_statements/migrated_0012.tree.json index c6fb0937971..8ecff2f02f5 100644 --- a/src/parser/test/flow/types/declare_statements/migrated_0012.tree.json +++ b/src/parser/test/flow/types/declare_statements/migrated_0012.tree.json @@ -59,6 +59,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":38},"end":{"line":1,"column":42}}, @@ -69,6 +71,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"set" diff --git a/src/parser/test/flow/types/declare_statements/migrated_0013.tree.json b/src/parser/test/flow/types/declare_statements/migrated_0013.tree.json index 3cb4cb83076..2be1c767a63 100644 --- a/src/parser/test/flow/types/declare_statements/migrated_0013.tree.json +++ b/src/parser/test/flow/types/declare_statements/migrated_0013.tree.json @@ -39,6 +39,8 @@ "loc":{"source":null,"start":{"line":1,"column":18},"end":{"line":1,"column":35}}, "range":[18,35], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":35}}, @@ -49,6 +51,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"get" @@ -90,6 +93,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":57},"end":{"line":1,"column":61}}, @@ -100,6 +105,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"set" diff --git a/src/parser/test/flow/types/declare_statements_invalid/migrated_0000.tree.json b/src/parser/test/flow/types/declare_statements_invalid/migrated_0000.tree.json index 6eebe34d2b6..8cf70e06b8e 100644 --- a/src/parser/test/flow/types/declare_statements_invalid/migrated_0000.tree.json +++ b/src/parser/test/flow/types/declare_statements_invalid/migrated_0000.tree.json @@ -31,6 +31,8 @@ "loc":{"source":null,"start":{"line":2,"column":20},"end":{"line":3,"column":0}}, "range":[54,58], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"AnyTypeAnnotation", "loc":{"source":null,"start":{"line":3,"column":0},"end":{"line":3,"column":0}}, diff --git a/src/parser/test/flow/types/declare_statements_invalid/migrated_0002.tree.json b/src/parser/test/flow/types/declare_statements_invalid/migrated_0002.tree.json index 9c78f173c13..3330e4c12dd 100644 --- a/src/parser/test/flow/types/declare_statements_invalid/migrated_0002.tree.json +++ b/src/parser/test/flow/types/declare_statements_invalid/migrated_0002.tree.json @@ -41,6 +41,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":true, "variance":null, "kind":"init" @@ -64,6 +65,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/exact_objects/migrated_0000.tree.json b/src/parser/test/flow/types/exact_objects/migrated_0000.tree.json index 74b6587c963..7605681b559 100644 --- a/src/parser/test/flow/types/exact_objects/migrated_0000.tree.json +++ b/src/parser/test/flow/types/exact_objects/migrated_0000.tree.json @@ -46,6 +46,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" @@ -69,6 +70,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/exact_objects/migrated_0001.tree.json b/src/parser/test/flow/types/exact_objects/migrated_0001.tree.json index ab606bc85da..55f1b74b195 100644 --- a/src/parser/test/flow/types/exact_objects/migrated_0001.tree.json +++ b/src/parser/test/flow/types/exact_objects/migrated_0001.tree.json @@ -46,6 +46,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" @@ -69,6 +70,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/function_predicates/migrated_0000.tree.json b/src/parser/test/flow/types/function_predicates/migrated_0000.tree.json index 3c9b7b701c9..d4f24b5a4ab 100644 --- a/src/parser/test/flow/types/function_predicates/migrated_0000.tree.json +++ b/src/parser/test/flow/types/function_predicates/migrated_0000.tree.json @@ -41,6 +41,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"BooleanTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":37}}, diff --git a/src/parser/test/flow/types/function_predicates/migrated_0001.tree.json b/src/parser/test/flow/types/function_predicates/migrated_0001.tree.json index 8cf682df268..e8059a36847 100644 --- a/src/parser/test/flow/types/function_predicates/migrated_0001.tree.json +++ b/src/parser/test/flow/types/function_predicates/migrated_0001.tree.json @@ -41,6 +41,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"BooleanTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":37}}, diff --git a/src/parser/test/flow/types/function_predicates/migrated_0005.tree.json b/src/parser/test/flow/types/function_predicates/migrated_0005.tree.json index 2f793cba166..f69aff06c7e 100644 --- a/src/parser/test/flow/types/function_predicates/migrated_0005.tree.json +++ b/src/parser/test/flow/types/function_predicates/migrated_0005.tree.json @@ -52,6 +52,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"BooleanTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":22},"end":{"line":1,"column":29}}, diff --git a/src/parser/test/flow/types/function_predicates/migrated_0006.tree.json b/src/parser/test/flow/types/function_predicates/migrated_0006.tree.json index ffb40922d72..40311056e7d 100644 --- a/src/parser/test/flow/types/function_predicates/migrated_0006.tree.json +++ b/src/parser/test/flow/types/function_predicates/migrated_0006.tree.json @@ -59,6 +59,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"BooleanTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":37}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0000.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0000.tree.json index ae1dfdcbd33..38846d5efd8 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0000.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0000.tree.json @@ -34,6 +34,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":25}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0001.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0001.tree.json index 3500fb66bb8..214a8b3355d 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0001.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0001.tree.json @@ -34,6 +34,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":22},"end":{"line":1,"column":26}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0002.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0002.tree.json index 7b0ca45116a..35001de0987 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0002.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0002.tree.json @@ -54,6 +54,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":28},"end":{"line":1,"column":32}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0003.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0003.tree.json index e0a591887d2..cff972dcebc 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0003.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0003.tree.json @@ -54,6 +54,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":29},"end":{"line":1,"column":33}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0004.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0004.tree.json index 8bb8454dd98..a714d46b1a8 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0004.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0004.tree.json @@ -53,6 +53,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":32},"end":{"line":1,"column":36}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0005.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0005.tree.json index ab5710c87df..4c122510190 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0005.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0005.tree.json @@ -21,6 +21,8 @@ "loc":{"source":null,"start":{"line":1,"column":9},"end":{"line":1,"column":35}}, "range":[9,35], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":31},"end":{"line":1,"column":35}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0006.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0006.tree.json index c97fa3d931a..2c151669077 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0006.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0006.tree.json @@ -54,6 +54,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":46},"end":{"line":1,"column":50}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0007.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0007.tree.json index 766826f65d7..1a0c5496e7d 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0007.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0007.tree.json @@ -75,6 +75,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberLiteralTypeAnnotation", "loc":{"source":null,"start":{"line":2,"column":28},"end":{"line":2,"column":31}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0010.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0010.tree.json index d0292abb51b..704e2350a17 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0010.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0010.tree.json @@ -68,6 +68,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberLiteralTypeAnnotation", "loc":{"source":null,"start":{"line":3,"column":26},"end":{"line":3,"column":29}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0014.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0014.tree.json index 5a3e7eedb35..150937a006c 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0014.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0014.tree.json @@ -34,6 +34,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":19},"end":{"line":1,"column":23}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0015.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0015.tree.json index 21612e2b21d..764143ae0ca 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0015.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0015.tree.json @@ -54,6 +54,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":26},"end":{"line":1,"column":30}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0018.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0018.tree.json index e2ca8f30ece..997b15ecc29 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0018.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0018.tree.json @@ -68,6 +68,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberLiteralTypeAnnotation", "loc":{"source":null,"start":{"line":3,"column":24},"end":{"line":3,"column":27}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0019.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0019.tree.json index 3a00f67bc32..a616c9556f0 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0019.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0019.tree.json @@ -44,6 +44,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"BooleanTypeAnnotation", "loc":{"source":null,"start":{"line":2,"column":28},"end":{"line":2,"column":35}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0020.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0020.tree.json index 6edce81253b..1077c5dcd88 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0020.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0020.tree.json @@ -44,6 +44,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"BooleanTypeAnnotation", "loc":{"source":null,"start":{"line":2,"column":28},"end":{"line":2,"column":35}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0021.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0021.tree.json index 04aeb66505e..c43d07ca5c2 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0021.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0021.tree.json @@ -39,6 +39,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"BooleanTypeAnnotation", "loc":{"source":null,"start":{"line":2,"column":20},"end":{"line":2,"column":27}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0022.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0022.tree.json index a828b84381d..09a3b5e0d61 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0022.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0022.tree.json @@ -39,6 +39,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"BooleanTypeAnnotation", "loc":{"source":null,"start":{"line":2,"column":21},"end":{"line":2,"column":28}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0023.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0023.tree.json index 3e7da955887..8328904bd62 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0023.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0023.tree.json @@ -44,6 +44,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"BooleanTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":20},"end":{"line":1,"column":27}}, @@ -55,6 +57,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":32},"end":{"line":1,"column":38}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0024.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0024.tree.json index 181fd4c6111..4de42baa948 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0024.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0024.tree.json @@ -34,6 +34,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"UnionTypeAnnotation", "loc":{"source":null,"start":{"line":2,"column":19},"end":{"line":2,"column":35}}, diff --git a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0025.tree.json b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0025.tree.json index df6ccb2cd01..15b9199a614 100644 --- a/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0025.tree.json +++ b/src/parser/test/flow/types/function_types_with_anonymous_parameters/migrated_0025.tree.json @@ -34,6 +34,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"FunctionTypeAnnotation", "loc":{"source":null,"start":{"line":2,"column":19},"end":{"line":2,"column":36}}, @@ -52,6 +54,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":2,"column":30},"end":{"line":2,"column":36}}, diff --git a/src/parser/test/flow/types/grouping/migrated_0001.tree.json b/src/parser/test/flow/types/grouping/migrated_0001.tree.json index 63efddd1a3f..7a65076186b 100644 --- a/src/parser/test/flow/types/grouping/migrated_0001.tree.json +++ b/src/parser/test/flow/types/grouping/migrated_0001.tree.json @@ -31,6 +31,8 @@ "loc":{"source":null,"start":{"line":1,"column":8},"end":{"line":1,"column":20}}, "range":[8,20], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":20}}, @@ -44,6 +46,8 @@ "loc":{"source":null,"start":{"line":1,"column":24},"end":{"line":1,"column":36}}, "range":[24,36], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"StringTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":30},"end":{"line":1,"column":36}}, diff --git a/src/parser/test/flow/types/grouping/migrated_0006.tree.json b/src/parser/test/flow/types/grouping/migrated_0006.tree.json index 05411811e39..d9d2e4e65ce 100644 --- a/src/parser/test/flow/types/grouping/migrated_0006.tree.json +++ b/src/parser/test/flow/types/grouping/migrated_0006.tree.json @@ -46,6 +46,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":27},"end":{"line":1,"column":33}}, diff --git a/src/parser/test/flow/types/instance_spread_invalid/migrated_0000.tree.json b/src/parser/test/flow/types/instance_spread_invalid/migrated_0000.tree.json index bbd5484f9fe..544bb67b1bb 100644 --- a/src/parser/test/flow/types/instance_spread_invalid/migrated_0000.tree.json +++ b/src/parser/test/flow/types/instance_spread_invalid/migrated_0000.tree.json @@ -7,10 +7,6 @@ { "loc":{"source":null,"start":{"line":1,"column":16},"end":{"line":1,"column":17}}, "message":"Unexpected identifier" - }, - { - "loc":{"source":null,"start":{"line":1,"column":17},"end":{"line":1,"column":18}}, - "message":"Unexpected token }" } ], "type":"Program", @@ -35,31 +31,7 @@ "loc":{"source":null,"start":{"line":1,"column":12},"end":{"line":1,"column":18}}, "range":[12,18], "exact":false, - "properties":[ - { - "type":"ObjectTypeProperty", - "loc":{"source":null,"start":{"line":1,"column":13},"end":{"line":1,"column":18}}, - "range":[13,18], - "key":{ - "type":"Identifier", - "loc":{"source":null,"start":{"line":1,"column":13},"end":{"line":1,"column":16}}, - "range":[13,16], - "name":"", - "typeAnnotation":null, - "optional":false - }, - "value":{ - "type":"AnyTypeAnnotation", - "loc":{"source":null,"start":{"line":1,"column":17},"end":{"line":1,"column":18}}, - "range":[17,18] - }, - "method":false, - "optional":false, - "static":false, - "variance":null, - "kind":"init" - } - ], + "properties":[], "indexers":[], "callProperties":[] }, diff --git a/src/parser/test/flow/types/instance_spread_invalid/migrated_0001.tree.json b/src/parser/test/flow/types/instance_spread_invalid/migrated_0001.tree.json index 1dd08e647ee..bfd96a06341 100644 --- a/src/parser/test/flow/types/instance_spread_invalid/migrated_0001.tree.json +++ b/src/parser/test/flow/types/instance_spread_invalid/migrated_0001.tree.json @@ -7,10 +7,6 @@ { "loc":{"source":null,"start":{"line":1,"column":20},"end":{"line":1,"column":21}}, "message":"Unexpected identifier" - }, - { - "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":22}}, - "message":"Unexpected token }" } ], "type":"Program", @@ -35,31 +31,7 @@ "loc":{"source":null,"start":{"line":1,"column":16},"end":{"line":1,"column":22}}, "range":[16,22], "exact":false, - "properties":[ - { - "type":"ObjectTypeProperty", - "loc":{"source":null,"start":{"line":1,"column":17},"end":{"line":1,"column":22}}, - "range":[17,22], - "key":{ - "type":"Identifier", - "loc":{"source":null,"start":{"line":1,"column":17},"end":{"line":1,"column":20}}, - "range":[17,20], - "name":"", - "typeAnnotation":null, - "optional":false - }, - "value":{ - "type":"AnyTypeAnnotation", - "loc":{"source":null,"start":{"line":1,"column":21},"end":{"line":1,"column":22}}, - "range":[21,22] - }, - "method":false, - "optional":false, - "static":false, - "variance":null, - "kind":"init" - } - ], + "properties":[], "indexers":[], "callProperties":[] }, diff --git a/src/parser/test/flow/types/interfaces/migrated_0002.tree.json b/src/parser/test/flow/types/interfaces/migrated_0002.tree.json index 78ccc0cefc3..d4d280e61aa 100644 --- a/src/parser/test/flow/types/interfaces/migrated_0002.tree.json +++ b/src/parser/test/flow/types/interfaces/migrated_0002.tree.json @@ -41,6 +41,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/interfaces/migrated_0010.tree.json b/src/parser/test/flow/types/interfaces/migrated_0010.tree.json index b0184b14de3..7a2ad76c6a2 100644 --- a/src/parser/test/flow/types/interfaces/migrated_0010.tree.json +++ b/src/parser/test/flow/types/interfaces/migrated_0010.tree.json @@ -41,6 +41,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/interfaces/prop_named_static.tree.json b/src/parser/test/flow/types/interfaces/prop_named_static.tree.json index 713f9c5ca85..1842adfce08 100644 --- a/src/parser/test/flow/types/interfaces/prop_named_static.tree.json +++ b/src/parser/test/flow/types/interfaces/prop_named_static.tree.json @@ -41,6 +41,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" @@ -89,6 +90,7 @@ }, "method":false, "optional":true, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/object/methods/generic_method.tree.json b/src/parser/test/flow/types/object/methods/generic_method.tree.json index 9df463b0ae9..3b0251c570b 100644 --- a/src/parser/test/flow/types/object/methods/generic_method.tree.json +++ b/src/parser/test/flow/types/object/methods/generic_method.tree.json @@ -68,6 +68,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":25},"end":{"line":1,"column":31}}, @@ -93,6 +95,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/object/methods/method.tree.json b/src/parser/test/flow/types/object/methods/method.tree.json index 73fea4603c8..4b4246d1f70 100644 --- a/src/parser/test/flow/types/object/methods/method.tree.json +++ b/src/parser/test/flow/types/object/methods/method.tree.json @@ -39,6 +39,8 @@ "loc":{"source":null,"start":{"line":1,"column":11},"end":{"line":1,"column":24}}, "range":[11,24], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":18},"end":{"line":1,"column":24}}, @@ -49,6 +51,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/object/unexpected_static.tree.json b/src/parser/test/flow/types/object/unexpected_static.tree.json index 1b207cbc0e1..e75069936cc 100644 --- a/src/parser/test/flow/types/object/unexpected_static.tree.json +++ b/src/parser/test/flow/types/object/unexpected_static.tree.json @@ -76,6 +76,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":true, "variance":null, "kind":"init" @@ -235,6 +236,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" @@ -291,6 +293,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":true, "variance":null, "kind":"init" @@ -330,6 +333,8 @@ "loc":{"source":null,"start":{"line":17,"column":17},"end":{"line":17,"column":22}}, "range":[483,488], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":17,"column":21},"end":{"line":17,"column":22}}, @@ -382,6 +387,8 @@ "loc":{"source":null,"start":{"line":20,"column":20},"end":{"line":20,"column":25}}, "range":[597,602], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":20,"column":24},"end":{"line":20,"column":25}}, diff --git a/src/parser/test/flow/types/object_type_property_variance/migrated_0000.tree.json b/src/parser/test/flow/types/object_type_property_variance/migrated_0000.tree.json index 7624f224e61..2ab12e8e2ab 100644 --- a/src/parser/test/flow/types/object_type_property_variance/migrated_0000.tree.json +++ b/src/parser/test/flow/types/object_type_property_variance/migrated_0000.tree.json @@ -50,6 +50,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/object_type_property_variance/migrated_0001.tree.json b/src/parser/test/flow/types/object_type_property_variance/migrated_0001.tree.json index aaa4832d72b..d64af2fddc4 100644 --- a/src/parser/test/flow/types/object_type_property_variance/migrated_0001.tree.json +++ b/src/parser/test/flow/types/object_type_property_variance/migrated_0001.tree.json @@ -50,6 +50,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":{ "type":"Variance", diff --git a/src/parser/test/flow/types/object_type_property_variance/migrated_0002.tree.json b/src/parser/test/flow/types/object_type_property_variance/migrated_0002.tree.json index 658678c3eda..d9bc1987dc9 100644 --- a/src/parser/test/flow/types/object_type_property_variance/migrated_0002.tree.json +++ b/src/parser/test/flow/types/object_type_property_variance/migrated_0002.tree.json @@ -50,6 +50,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":{ "type":"Variance", diff --git a/src/parser/test/flow/types/object_type_property_variance/migrated_0003.tree.json b/src/parser/test/flow/types/object_type_property_variance/migrated_0003.tree.json index b03a33f9378..45a430fb0db 100644 --- a/src/parser/test/flow/types/object_type_property_variance/migrated_0003.tree.json +++ b/src/parser/test/flow/types/object_type_property_variance/migrated_0003.tree.json @@ -39,6 +39,8 @@ "loc":{"source":null,"start":{"line":1,"column":10},"end":{"line":1,"column":15}}, "range":[10,15], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":15}}, @@ -58,6 +60,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/object_type_property_variance/migrated_0004.tree.json b/src/parser/test/flow/types/object_type_property_variance/migrated_0004.tree.json index 7be4583e281..80150729c8b 100644 --- a/src/parser/test/flow/types/object_type_property_variance/migrated_0004.tree.json +++ b/src/parser/test/flow/types/object_type_property_variance/migrated_0004.tree.json @@ -45,6 +45,8 @@ "loc":{"source":null,"start":{"line":1,"column":10},"end":{"line":1,"column":16}}, "range":[10,16], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":15},"end":{"line":1,"column":16}}, @@ -64,6 +66,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/object_type_property_variance/migrated_0005.tree.json b/src/parser/test/flow/types/object_type_property_variance/migrated_0005.tree.json index 7be4583e281..80150729c8b 100644 --- a/src/parser/test/flow/types/object_type_property_variance/migrated_0005.tree.json +++ b/src/parser/test/flow/types/object_type_property_variance/migrated_0005.tree.json @@ -45,6 +45,8 @@ "loc":{"source":null,"start":{"line":1,"column":10},"end":{"line":1,"column":16}}, "range":[10,16], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":15},"end":{"line":1,"column":16}}, @@ -64,6 +66,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/object_type_property_variance/migrated_0009.tree.json b/src/parser/test/flow/types/object_type_property_variance/migrated_0009.tree.json index 0f9b29074c1..acb98504996 100644 --- a/src/parser/test/flow/types/object_type_property_variance/migrated_0009.tree.json +++ b/src/parser/test/flow/types/object_type_property_variance/migrated_0009.tree.json @@ -33,6 +33,8 @@ "loc":{"source":null,"start":{"line":1,"column":10},"end":{"line":1,"column":14}}, "range":[10,14], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":13},"end":{"line":1,"column":14}}, diff --git a/src/parser/test/flow/types/object_type_property_variance/migrated_0010.tree.json b/src/parser/test/flow/types/object_type_property_variance/migrated_0010.tree.json index d16081b4435..0f47885bd62 100644 --- a/src/parser/test/flow/types/object_type_property_variance/migrated_0010.tree.json +++ b/src/parser/test/flow/types/object_type_property_variance/migrated_0010.tree.json @@ -39,6 +39,8 @@ "loc":{"source":null,"start":{"line":1,"column":11},"end":{"line":1,"column":15}}, "range":[11,15], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":15}}, diff --git a/src/parser/test/flow/types/object_type_property_variance/migrated_0011.tree.json b/src/parser/test/flow/types/object_type_property_variance/migrated_0011.tree.json index d16081b4435..0f47885bd62 100644 --- a/src/parser/test/flow/types/object_type_property_variance/migrated_0011.tree.json +++ b/src/parser/test/flow/types/object_type_property_variance/migrated_0011.tree.json @@ -39,6 +39,8 @@ "loc":{"source":null,"start":{"line":1,"column":11},"end":{"line":1,"column":15}}, "range":[11,15], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"GenericTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":14},"end":{"line":1,"column":15}}, diff --git a/src/parser/test/flow/types/object_type_spread/migrated_0002.tree.json b/src/parser/test/flow/types/object_type_spread/migrated_0002.tree.json index ac5f5b60cb1..1836ba0f7da 100644 --- a/src/parser/test/flow/types/object_type_spread/migrated_0002.tree.json +++ b/src/parser/test/flow/types/object_type_spread/migrated_0002.tree.json @@ -50,6 +50,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/object_type_spread/migrated_0003.tree.json b/src/parser/test/flow/types/object_type_spread/migrated_0003.tree.json index 5ac3824066e..3fac6e7b395 100644 --- a/src/parser/test/flow/types/object_type_spread/migrated_0003.tree.json +++ b/src/parser/test/flow/types/object_type_spread/migrated_0003.tree.json @@ -69,6 +69,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/parameter_defaults/migrated_0027.tree.json b/src/parser/test/flow/types/parameter_defaults/migrated_0027.tree.json index d94c2059d2d..ac36fcd55dd 100644 --- a/src/parser/test/flow/types/parameter_defaults/migrated_0027.tree.json +++ b/src/parser/test/flow/types/parameter_defaults/migrated_0027.tree.json @@ -43,6 +43,8 @@ "loc":{"source":null,"start":{"line":1,"column":20},"end":{"line":1,"column":37}}, "range":[20,37], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"AnyTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":36},"end":{"line":1,"column":37}}, diff --git a/src/parser/test/flow/types/parameter_defaults/migrated_0031.tree.json b/src/parser/test/flow/types/parameter_defaults/migrated_0031.tree.json index 35252418b6c..1a2a60ca892 100644 --- a/src/parser/test/flow/types/parameter_defaults/migrated_0031.tree.json +++ b/src/parser/test/flow/types/parameter_defaults/migrated_0031.tree.json @@ -49,6 +49,8 @@ "loc":{"source":null,"start":{"line":1,"column":18},"end":{"line":1,"column":41}}, "range":[18,41], "params":[], + "async":false, + "generator":false, "returnType":{ "type":"VoidTypeAnnotation", "loc":{"source":null,"start":{"line":1,"column":37},"end":{"line":1,"column":41}}, @@ -83,6 +85,7 @@ }, "method":true, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/typecasts/migrated_0001.tree.json b/src/parser/test/flow/types/typecasts/migrated_0001.tree.json index d43765fb5c3..a8e65cc0629 100644 --- a/src/parser/test/flow/types/typecasts/migrated_0001.tree.json +++ b/src/parser/test/flow/types/typecasts/migrated_0001.tree.json @@ -95,6 +95,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" @@ -118,6 +119,7 @@ }, "method":false, "optional":false, + "abstract":false, "static":false, "variance":null, "kind":"init" diff --git a/src/parser/test/flow/types/typecasts/migrated_0002.tree.json b/src/parser/test/flow/types/typecasts/migrated_0002.tree.json index ee362aaa895..9ae004cec1a 100644 --- a/src/parser/test/flow/types/typecasts/migrated_0002.tree.json +++ b/src/parser/test/flow/types/typecasts/migrated_0002.tree.json @@ -83,6 +83,8 @@ "optional":false } ], + "async":false, + "generator":false, "returnType":{ "type":"NumberTypeAnnotation", "loc":{"source":null,"start":{"line":2,"column":36},"end":{"line":2,"column":42}}, diff --git a/src/parser/test/print_ast.js b/src/parser/test/print_ast.js new file mode 100755 index 00000000000..73df7826663 --- /dev/null +++ b/src/parser/test/print_ast.js @@ -0,0 +1,67 @@ +#!/usr/bin/env node + +/* + * `cat FILE | print_ast.js [OPTIONS]` + * + * Print the AST of JavaScript file named FILE to stdout. An optional file + * named OPTIONS provides JSON formatted options to the Flow parser. See + * `flow.org/en/docs/config/options/#toc-available-options` for available + * options. + */ + +const parser = require("../flow_parser"); +const fs = require("fs"); + +const arg = process.argv[2] +const options = (arg && JSON.parse(fs.readFileSync(process.cwd() + "/" + arg))) || {}; + +const stdin = process.stdin; +const stdout = process.stdout; +const stderr = process.stderr; + +let text = ""; + +let js = new Promise((resolve, reject) => { + stdin.setEncoding("utf8"); + + stdin.on("readable", () => { + let chunk; + + while ((chunk = stdin.read())) { + text += chunk; + } + }); + + stdin.on("end", () => { + resolve(text); + }); +}); + +function pretty_print(key, value) { + switch (key) { + case "loc": + case "range": + return JSON.stringify(value); + default: + return value; + } +} + +function process_line(line) { + const unescaped = /(^)"|([^\\])"/g; + const escaped = /\\\"/g; + if (line.match(/^ *\"loc\":|^ *\"range\":/)) { + const parts = line.split(":"); + const key = parts.shift(); + const value = parts.join(":"); + return key + ":" + value.replace(unescaped, "$2").replace(escaped, "\""); + } else { + return line; + } +} + +js.then(text => JSON.stringify(parser.parse(text, options), pretty_print, 2)) + .then(text => text.replace(/\": /g, "\":")) + .then(text => text.split("\n").map(process_line).join("\n")) + .then(text => stdout.write(text + "\n")) + .catch(err => stderr.write(err + "\n")); diff --git a/src/parser/token.ml b/src/parser/token.ml index 303dcb808dd..d24992e2052 100644 --- a/src/parser/token.ml +++ b/src/parser/token.ml @@ -80,6 +80,7 @@ type t = | T_ASYNC | T_AWAIT | T_CHECKS + | T_ABSTRACT (* Operators *) | T_RSHIFT3_ASSIGN | T_RSHIFT_ASSIGN @@ -219,6 +220,7 @@ let token_to_string = function | T_ASYNC -> "T_ASYNC" | T_AWAIT -> "T_AWAIT" | T_CHECKS -> "T_CHECKS" + | T_ABSTRACT -> "T_ABSTRACT" | T_LCURLY -> "T_LCURLY" | T_RCURLY -> "T_RCURLY" | T_LCURLYBAR -> "T_LCURLYBAR" @@ -363,6 +365,7 @@ let value_of_token = function | T_ASYNC -> "async" | T_AWAIT -> "await" | T_CHECKS -> "%checks" + | T_ABSTRACT -> "abstract" | T_RSHIFT3_ASSIGN -> ">>>=" | T_RSHIFT_ASSIGN -> ">>=" | T_LSHIFT_ASSIGN -> "<<=" diff --git a/src/parser/type_parser.ml b/src/parser/type_parser.ml index 16e0d13db84..1eba9441f5b 100644 --- a/src/parser/type_parser.ml +++ b/src/parser/type_parser.ml @@ -18,7 +18,7 @@ module type TYPE = sig val type_parameter_declaration_with_defaults : env -> Loc.t Ast.Type.ParameterDeclaration.t option val type_parameter_instantiation : env -> Loc.t Ast.Type.ParameterInstantiation.t option val generic : env -> Loc.t * Loc.t Ast.Type.Generic.t - val _object : allow_static:bool -> env -> Loc.t * Loc.t Type.Object.t + val _object : allow_abstract:bool -> allow_static:bool -> env -> Loc.t * Loc.t Type.Object.t val function_param_list : env -> Loc.t Type.Function.Params.t val annotation : env -> Loc.t Ast.Type.annotation val annotation_opt : env -> Loc.t Ast.Type.annotation option @@ -160,8 +160,8 @@ module Type (Parse: Parser_common.PARSER) : TYPE = struct | T_LPAREN -> function_or_group env | T_LCURLY | T_LCURLYBAR -> - let loc, o = _object env - ~allow_static:false ~allow_exact:true ~allow_spread:true in + let loc, o = _object ~allow_abstract:false ~allow_static:false + ~allow_exact:true ~allow_spread:true env in loc, Type.Object o | T_TYPEOF -> let start_loc = Peek.loc env in @@ -170,6 +170,7 @@ module Type (Parse: Parser_common.PARSER) : TYPE = struct Loc.btwn start_loc (fst t), Type.Typeof t | T_LBRACKET -> tuple env | T_IDENTIFIER _ + | T_ABSTRACT | T_STATIC (* `static` is reserved in strict mode, but still an identifier *) -> let loc, g = generic env in loc, Type.Generic g @@ -386,6 +387,8 @@ module Type (Parse: Parser_common.PARSER) : TYPE = struct let end_loc = fst returnType in Loc.btwn start_loc end_loc, Type.(Function Function.({ params; + async = false; + generator = false; returnType; typeParameters; })) @@ -398,30 +401,33 @@ module Type (Parse: Parser_common.PARSER) : TYPE = struct let loc = Loc.btwn start_loc (fst returnType) in loc, Type.Function.({ params; + async = false; + generator = false; returnType; typeParameters = type_params; }) - in let method_property env start_loc static key = + in let method_property env start_loc abstract static key = let type_params = type_parameter_declaration ~allow_default:false env in let value = methodish env start_loc type_params in let value = fst value, Type.Function (snd value) in - Type.Object.(Property (fst value, Property.({ + fst value, Type.Object.Property.({ key; value = Init value; optional = false; - static; + abstract = abstract <> None; + static = static <> None; _method = true; variance = None; - }))) + }) in let call_property env start_loc static = let type_params = type_parameter_declaration ~allow_default:false env in let value = methodish env (Peek.loc env) type_params in - Type.Object.(CallProperty (Loc.btwn start_loc (fst value), CallProperty.({ + Loc.btwn start_loc (fst value), Type.Object.CallProperty.({ value; - static; - }))) + static = static <> None; + }) in let property env start_loc static variance key = if not (should_parse_types env) @@ -429,14 +435,15 @@ module Type (Parse: Parser_common.PARSER) : TYPE = struct let optional = Expect.maybe env T_PLING in Expect.token env T_COLON; let value = _type env in - Type.Object.(Property (Loc.btwn start_loc (fst value), Property.({ + Loc.btwn start_loc (fst value), Type.Object.Property.({ key; value = Init value; optional; - static; + abstract = false; + static = static <> None; _method = false; variance; - }))) + }) in let getter_or_setter ~is_getter env start_loc static key = let value = methodish env start_loc None in @@ -451,14 +458,15 @@ module Type (Parse: Parser_common.PARSER) : TYPE = struct | true, _ -> error_at env (key_loc, Error.GetterArity) | false, _ -> error_at env (key_loc, Error.SetterArity) end; - Type.Object.(Property (Loc.btwn start_loc (fst value), Property.({ + Loc.btwn start_loc (fst value), Type.Object.Property.({ key; value = if is_getter then Get value else Set value; optional = false; - static; + abstract = false; + static = static <> None; _method = false; variance = None; - }))) + }) in let indexer_property env start_loc static variance = Expect.token env T_LBRACKET; @@ -473,13 +481,13 @@ module Type (Parse: Parser_common.PARSER) : TYPE = struct Expect.token env T_RBRACKET; Expect.token env T_COLON; let value = _type env in - Type.Object.(Indexer (Loc.btwn start_loc (fst value), Indexer.({ + Loc.btwn start_loc (fst value), Type.Object.Indexer.({ id; key; value; - static; + static = static <> None; variance; - }))) + }) in let semicolon exact env = match Peek.token env with @@ -488,123 +496,196 @@ module Type (Parse: Parser_common.PARSER) : TYPE = struct | T_RCURLY when not exact -> () | _ -> error_unexpected env - in let error_unsupported_variance env = function - | Some (loc, _) -> error_at env (loc, Error.UnexpectedVariance) - | None -> () + in let module Members = struct + include Object_members.Make(struct + type internal_t = Loc.t Type.Object.property + + module PropertyParam = struct + type t = Loc.t Type.Object.Property.t + type internal_t = Loc.t Type.Object.property + let loc (loc, _) = loc + let name (_, p) = Object_members.property_name p.Type.Object.Property.key + let is_static (_, p) = p.Type.Object.Property.static + let intern t = Type.Object.Property t + end + module AbstractMethod = Object_members.AbstractMethod(PropertyParam) + module Method = Object_members.Method(PropertyParam) + module Property = Object_members.Property(PropertyParam) + module Getter = Object_members.Getter(PropertyParam) + module Setter = Object_members.Setter(PropertyParam) + end) + + let error_unsupported_variance env = function + | Some (loc, _) -> error_at env (loc, Error.UnexpectedVariance) + | None -> () + + let add_indexer env abstract i t = + abstract |> (function + | Some _ -> error_at env (fst i, Error.AbstractIndexer) + | None -> ()); + add_member (Type.Object.Indexer i) t + + let add_call env variance c t = + error_unsupported_variance env variance; + add_member (Type.Object.CallProperty c) t - in let error_if_unexpected_static env ~allow_static = function - | Some loc when not allow_static -> - error_at env (loc, Error.UnexpectedStatic) - | _ -> () + let add_spread env variance s t = + error_unsupported_variance env variance; + add_member (Type.Object.SpreadProperty s) t + end - in let rec properties ~allow_static ~allow_spread ~exact env acc = + in let prelude_keywords env = + let id_opt name = function + | Some loc -> Some (loc, name) + | None -> None + in + let loc = Peek.loc env in + let abstract = if Expect.maybe env T_ABSTRACT then Some loc else None in + match Peek.token env with + | T_LESS_THAN + | T_LPAREN + | T_PLING + | T_COLON -> + ((None, None), id_opt "abstract" abstract) + | _ -> + let loc = Peek.loc env in + let static = if Expect.maybe env T_STATIC then Some loc else None in + match Peek.token env with + | T_LESS_THAN + | T_LPAREN when abstract <> None -> + ((abstract, None), id_opt "static" static) + | T_PLING + | T_COLON -> + ((abstract, None), id_opt "static" static) + | _ -> + ((abstract, static), None) + + in let rec properties ~allow_abstract ~allow_static ~allow_spread ~exact env acc = assert (not (allow_static && allow_spread)); (* no `static ...A` *) let start_loc = Peek.loc env in - let static, static_loc = match Peek.token env with - | T_STATIC -> - Eat.token env; - true, Some start_loc - | _ -> false, None - in + let ((abstract, static), key) = prelude_keywords env in + abstract |> (function + | Some loc when not allow_abstract -> + error_at env (loc, Error.UnexpectedAbstract) + | _ -> ()); + static |> (function + | Some loc when not allow_static -> + error_at env (loc, Error.UnexpectedStatic) + | _ -> ()); let variance = variance env in + let object_id id = Expression.Object.Property.Identifier id in + let object_key env = + Eat.push_lex_mode env Lex_mode.NORMAL; + let result = Parse.object_key env in + Eat.pop_lex_mode env; + result + in match Peek.token env with - | T_EOF -> - error_if_unexpected_static env ~allow_static static_loc; - List.rev acc - | T_RCURLYBAR when exact -> - error_if_unexpected_static env ~allow_static static_loc; - List.rev acc - | T_RCURLY when not exact -> - error_if_unexpected_static env ~allow_static static_loc; - List.rev acc - | T_LBRACKET -> - error_if_unexpected_static env ~allow_static static_loc; - let indexer = indexer_property env start_loc static variance in - semicolon exact env; - properties ~allow_static ~allow_spread ~exact env (indexer::acc) - | T_LESS_THAN - | T_LPAREN -> - error_if_unexpected_static env ~allow_static static_loc; - error_unsupported_variance env variance; - let call_prop = call_property env start_loc static in - semicolon exact env; - properties ~allow_static ~allow_spread ~exact env (call_prop::acc) - | T_ELLIPSIS when allow_spread -> - error_if_unexpected_static env ~allow_static static_loc; - error_unsupported_variance env variance; - Eat.token env; - let (arg_loc, _) as argument = _type env in - let loc = Loc.btwn start_loc arg_loc in - let property = Type.Object.(SpreadProperty (loc, { SpreadProperty. - argument; - })) in - semicolon exact env; - properties ~allow_static ~allow_spread ~exact env (property::acc) + | T_EOF + | T_RCURLYBAR + | T_RCURLY -> + begin match abstract, static, variance with + | Some _, _, _ + | _, Some _, _ + | _, _, Some _ -> + error_unexpected env + | _ -> () + end; + acc | token -> - let property = match static, variance, token with - | true, None, (T_PLING | T_COLON) -> - let key = Expression.Object.Property.Identifier ( - start_loc, - "static" - ) in - let static = false in - begin match Peek.token env with + let acc = match token with | T_LESS_THAN | T_LPAREN -> - error_unsupported_variance env variance; - method_property env start_loc static key - | _ -> - property env start_loc static variance key - end - | _ -> - error_if_unexpected_static env ~allow_static static_loc; - let object_key env = - Eat.push_lex_mode env Lex_mode.NORMAL; - let result = Parse.object_key env in - Eat.pop_lex_mode env; - result - in - begin match object_key env with - | _, (Expression.Object.Property.Identifier - (_, ("get" | "set" as name)) as key) -> + begin match key with + | Some k -> + let key = object_id k in + let m = method_property env start_loc abstract static key in + if abstract <> None + then Members.add_abstract_method env variance m acc + else Members.add_method env variance m acc + | None -> + let c = call_property env start_loc static in + Members.add_call env variance c acc + end + | T_PLING + | T_COLON -> + begin match key with + | Some k -> + let key = object_id k in + let p = property env start_loc static variance key in + Members.add_property env abstract p acc + | None -> + error_unexpected env; + Eat.token env; + acc + end + | T_IDENTIFIER { raw = "get" | "set" as name; _ } -> + let et = object_id (Peek.loc env, name) in + Eat.token env; begin match Peek.token env with | T_LESS_THAN | T_LPAREN -> - error_unsupported_variance env variance; - method_property env start_loc static key - | T_COLON - | T_PLING -> - property env start_loc static variance key + let m = method_property env start_loc abstract static et in + if abstract <> None + then Members.add_abstract_method env variance m acc + else Members.add_method env variance m acc + | T_PLING + | T_COLON -> + let p = property env start_loc static variance et in + Members.add_property env abstract p acc | _ -> - let key = object_key env in - let is_getter = name = "get" in - error_unsupported_variance env variance; - getter_or_setter ~is_getter env start_loc static key + let key = object_key env in + if name = "get" then + let getter_property = getter_or_setter ~is_getter:true in + let p = getter_property env start_loc static key in + Members.add_getter env abstract variance p acc + else + let setter_property = getter_or_setter ~is_getter:false in + let p = setter_property env start_loc static key in + Members.add_setter env abstract variance p acc end - | _, key -> + | T_LBRACKET -> + let i = indexer_property env start_loc static variance in + Members.add_indexer env abstract i acc + | T_ELLIPSIS when allow_spread -> + Eat.token env; + let (arg_loc, _) as argument = _type env in + let loc = Loc.btwn start_loc arg_loc in + let s = loc, { Type.Object.SpreadProperty.argument; } in + Members.add_spread env variance s acc + | _ -> + let _, key = object_key env in begin match Peek.token env with | T_LESS_THAN | T_LPAREN -> - error_unsupported_variance env variance; - method_property env start_loc static key + let m = method_property env start_loc abstract static key in + if abstract <> None + then Members.add_abstract_method env variance m acc + else Members.add_method env variance m acc + | T_PLING + | T_COLON -> + let p = property env start_loc static variance key in + Members.add_property env abstract p acc | _ -> - property env start_loc static variance key + error_unexpected env; + Eat.token env; + acc end - end - in - semicolon exact env; - properties ~allow_static ~allow_spread ~exact env (property::acc) + in + semicolon exact env; + properties ~allow_abstract ~allow_static ~allow_spread ~exact env acc - in fun ~allow_static ~allow_exact ~allow_spread env -> + in fun ~allow_abstract ~allow_static ~allow_exact ~allow_spread env -> let exact = allow_exact && Peek.token env = T_LCURLYBAR in let start_loc = Peek.loc env in Expect.token env (if exact then T_LCURLYBAR else T_LCURLY); - let properties = properties ~allow_static ~exact ~allow_spread env [] in + let properties = properties ~allow_abstract ~allow_static + ~exact ~allow_spread env Object_members.empty in let end_loc = Peek.loc env in Expect.token env (if exact then T_RCURLYBAR else T_RCURLY); Loc.btwn start_loc end_loc, Type.Object.({ exact; - properties; + properties = Object_members.members properties; }) and type_identifier env = @@ -769,8 +850,8 @@ module Type (Parse: Parser_common.PARSER) : TYPE = struct let type_parameter_declaration = wrap (type_parameter_declaration ~allow_default:false) let type_parameter_instantiation = wrap type_parameter_instantiation - let _object ~allow_static env = - wrap (_object ~allow_static ~allow_exact:false ~allow_spread:false) env + let _object ~allow_abstract ~allow_static env = + wrap (_object ~allow_abstract ~allow_static ~allow_exact:false ~allow_spread:false) env let function_param_list = wrap function_param_list let annotation = wrap annotation let annotation_opt = wrap annotation_opt diff --git a/src/parser_utils/comment_attacher.ml b/src/parser_utils/comment_attacher.ml index 05e71c8fe51..eba914591b0 100644 --- a/src/parser_utils/comment_attacher.ml +++ b/src/parser_utils/comment_attacher.ml @@ -79,6 +79,7 @@ class comment_attacher ~comments = object(this) method! class_element (elem: Loc.t Ast.Class.Body.element) = let open Ast.Class.Body in begin match elem with + | AbstractMethod (loc, _) | Method (loc, _) | Property (loc, _) | PrivateField (loc, _) -> this#check_loc loc diff --git a/src/parser_utils/flow_ast_mapper.ml b/src/parser_utils/flow_ast_mapper.ml index 9d48a7718d2..c2589733fb9 100644 --- a/src/parser_utils/flow_ast_mapper.ml +++ b/src/parser_utils/flow_ast_mapper.ml @@ -266,11 +266,21 @@ class mapper = object(this) method class_element (elem: Loc.t Ast.Class.Body.element) = let open Ast.Class.Body in match elem with + | AbstractMethod (loc, meth) -> id this#abstract_class_method meth elem + (fun meth -> AbstractMethod (loc, meth)) | Method (loc, meth) -> id this#class_method meth elem (fun meth -> Method (loc, meth)) | Property (loc, prop) -> id this#class_property prop elem (fun prop -> Property (loc, prop)) | PrivateField (loc, field) -> id this#class_private_field field elem (fun field -> PrivateField (loc, field)) + method abstract_class_method (meth: Loc.t Ast.Class.AbstractMethod.t') = + let open Ast.Class.AbstractMethod in + let { key; value; static = _; } = meth in + let key' = this#identifier key in + let value' = map_loc this#function_type value in + if key == key' && value == value' then meth + else { meth with key = key'; value = value' } + method class_method (meth: Loc.t Ast.Class.Method.t') = let open Ast.Class.Method in let { kind = _; key; value; static = _; decorators = _; } = meth in @@ -502,6 +512,8 @@ class mapper = object(this) let open Ast.Type.Function in let { params = (params_loc, { Params.params = ps; rest = rpo }); + async; + generator; returnType; typeParameters; } = ft in @@ -511,6 +523,8 @@ class mapper = object(this) if ps' == ps && rpo' == rpo && returnType' == returnType then ft else { params = (params_loc, { Params.params = ps'; rest = rpo' }); + async; + generator; returnType = returnType'; typeParameters } @@ -527,10 +541,10 @@ class mapper = object(this) method object_property_type (opt: Loc.t Ast.Type.Object.Property.t) = let open Ast.Type.Object.Property in - let loc, { key; value; optional; static; _method; variance; } = opt in + let loc, { key; value; optional; abstract; static; _method; variance; } = opt in let value' = this#object_property_value_type value in if value' == value then opt - else loc, { key; value = value'; optional; static; _method; variance } + else loc, { key; value = value'; optional; abstract; static; _method; variance; } method object_type (ot: Loc.t Ast.Type.Object.t) = let open Ast.Type.Object in diff --git a/src/services/flowFileGen/flowFileGen.ml b/src/services/flowFileGen/flowFileGen.ml index 765e5220fb2..ee7e2960095 100644 --- a/src/services/flowFileGen/flowFileGen.ml +++ b/src/services/flowFileGen/flowFileGen.ml @@ -24,7 +24,7 @@ let exports_map cx module_name = let rec mark_declared_classes name t env = Codegen.(Type.( match resolve_type t env with - | ThisClassT (_, DefT (_, InstanceT (_, _, _, {class_id; _;}))) -> + | ThisClassT (_, DefT (_, InstanceT (_, _, _, {class_id; _;})), _) -> set_class_name class_id name env | DefT (_, PolyT (_, t, _)) -> mark_declared_classes name t env @@ -119,7 +119,7 @@ let gen_class_body = *) let is_static_name_field = static && field_name = "name" && ( match p with - | Field (_, t, _) -> + | Field ((_, _, t), _) -> (match resolve_type t env with | DefT (_, StrT AnyLiteral) -> true | _ -> false) @@ -128,7 +128,7 @@ let gen_class_body = let is_empty_constructor = not static && field_name = "constructor" && ( match p with - | Method (_, t) -> + | Method (_, _, t) -> (match resolve_type t env with | DefT (_, FunT (_, _, { params; return_t; _ })) -> (params = []) && ( @@ -144,8 +144,7 @@ let gen_class_body = then env else ( add_str " " env - |> gen_if static (add_str "static ") - |> gen_prop field_name p + |> gen_prop ~static field_name p |> add_str ";\n" ) )) in @@ -192,17 +191,18 @@ class unexported_class_visitor = object(self) let seen = TypeSet.add t seen in match t with (* class_id = 0 is top of the inheritance chain *) - | DefT (_, InstanceT (_, _, _, {class_id; _;})) + | ThisClassT (_, DefT (_, InstanceT (_, _, _, {class_id; _;})), _) when class_id = 0 || ISet.mem class_id imported_classids -> (env, seen, imported_classids) - | DefT (r, InstanceT (static, extends, implements, { + | ThisClassT (_, DefT (r, InstanceT (static, extends, implements, { class_id; fields_tmap; methods_tmap; structural; _ - })) when not (has_class_name class_id env || Reason.is_lib_reason r) -> + })), _) + when not (has_class_name class_id env || Reason.is_lib_reason r) -> let class_name = next_class_name env in (** @@ -221,7 +221,7 @@ class unexported_class_visitor = object(self) let env = match resolve_type extends env with | ObjProtoT _ -> env - | DefT (_, ClassT t) when ( + | DefT (_, ClassT (t, _)) when ( match resolve_type t env with | ObjProtoT _ -> true | _ -> false ) -> env | ThisTypeAppT (_, extends, _, None) -> @@ -244,9 +244,13 @@ class unexported_class_visitor = object(self) let fields = find_props fields_tmap env in let methods = find_props methods_tmap env in - let env = gen_class_body static fields methods env |> add_str "\n" in + let env = + gen_class_body static fields methods env |> add_str "\n" in (env, seen, imported_classids) + | DefT (_, InstanceT _) -> + failwith "Internal Error: `unexported_class_visitor` reached an InstanceT" + | t -> super#type_ cx pole (env, seen, imported_classids) t ) )) @@ -282,7 +286,7 @@ let gen_local_classes = in let rec fold_imported_classid _name t set = Type.( match Codegen.resolve_type t env with - | ThisClassT (_, DefT (_, InstanceT (_, _, _, {class_id; _;}))) -> + | ThisClassT (_, DefT (_, InstanceT (_, _, _, {class_id; _;})), _) -> ISet.add class_id set | DefT (_, PolyT (_, t, _)) -> fold_imported_classid _name t set | _ -> set @@ -328,7 +332,7 @@ let gen_named_exports = mixins = _; structural; _; - }))) -> + })), _) -> let fields = Codegen.find_props fields_tmap env in let methods = Codegen.find_props methods_tmap env in let env = add_str "declare export " env in diff --git a/src/typing/class_sig.ml b/src/typing/class_sig.ml index 6c99e2c3a82..ab2a5d0f7ef 100644 --- a/src/typing/class_sig.ml +++ b/src/typing/class_sig.ml @@ -10,19 +10,23 @@ module Flow = Flow_js open Reason -type field = Loc.t option * Type.polarity * field' -and field' = Annot of Type.t | Infer of Func_sig.t +type field = fld * Type.polarity +and fld = Type.Property.kind * Loc.t option * field_t +and field_t = Annot of Type.t | Infer of Func_sig.t + +type meth = Type.Property.kind * Loc.t option * Func_sig.t type signature = { reason: reason; super: Type.t; fields: field SMap.t; private_fields: field SMap.t; + abstracts: meth SMap.t; (* Multiple function signatures indicates an overloaded method. Note that function signatures are stored in reverse definition order. *) - methods: (Loc.t option * Func_sig.t) Nel.t SMap.t; - getters: (Loc.t option * Func_sig.t) SMap.t; - setters: (Loc.t option * Func_sig.t) SMap.t; + methods: meth Nel.t SMap.t; + getters: meth SMap.t; + setters: meth SMap.t; } type t = { @@ -33,7 +37,7 @@ type t = { implements: Type.t list; (* Multiple function signatures indicates an overloaded constructor. Note that function signatures are stored in reverse definition order. *) - constructor: (Loc.t option * Func_sig.t) list; + constructor: meth list; static: signature; instance: signature; } @@ -58,6 +62,7 @@ let empty id reason tparams tparams_map super = reason; super; fields = SMap.empty; private_fields = SMap.empty; + abstracts = SMap.empty; methods = SMap.empty; getters = SMap.empty; setters = SMap.empty; @@ -76,7 +81,7 @@ let empty id reason tparams tparams_map super = | [] -> t0 | t1::ts -> DefT (super_reason, IntersectionT (InterRep.make t0 t1 ts)) in - super, class_type super + super, nonabstract_class_type super in (* If the interface definition includes a callable property, add the function prototype to the super type. *) @@ -93,7 +98,7 @@ let empty id reason tparams tparams_map super = bind, call, and apply. Despite this, classes are generally not callable without new (exceptions include cast functions like Number). *) let super, ssuper = match extends with - | Explicit t -> t, class_type t + | Explicit t -> t, nonabstract_class_type t | Implicit { null } -> (* The builtin Object class represents the top of the prototype chain, so it's super type should be `null` to signify the end. *) @@ -126,6 +131,8 @@ let empty id reason tparams tparams_map super = { id; structural; tparams; tparams_map; constructor; static; instance; implements } +let map_third f (e1, e2, e3) = (e1, e2, f e3) + let map_sig ~static f s = if static then {s with static = f s.static} @@ -134,71 +141,89 @@ let map_sig ~static f s = let with_sig ~static f s = if static then f s.static else f s.instance -let add_private_field name fld = map_sig (fun s -> { +let add_private_field name fld polarity = map_sig (fun s -> { s with - private_fields = SMap.add name fld s.private_fields; + private_fields = SMap.add name (fld, polarity) s.private_fields; }) -let add_constructor loc fsig s = - {s with constructor = [loc, Func_sig.to_ctor_sig fsig]} +let add_constructor meth s = { + s with constructor = [map_third Func_sig.to_ctor_sig meth] +} let add_default_constructor reason s = + let kind = Type.Property.Member ("constructor", loc_of_reason reason) in let fsig = Func_sig.default_constructor reason in - add_constructor None fsig s + add_constructor (kind, None, fsig) s -let append_constructor loc fsig s = - {s with constructor = (loc, Func_sig.to_ctor_sig fsig)::s.constructor} +let append_constructor meth s = { + s with constructor = (map_third Func_sig.to_ctor_sig meth)::s.constructor +} -let add_field ~static name fld = map_sig ~static (fun s -> { +let add_field ~static name fld polarity = map_sig ~static (fun s -> { s with - fields = SMap.add name fld s.fields; + fields = SMap.add name (fld, polarity) s.fields; methods = if static then SMap.remove name s.methods else s.methods; getters = SMap.remove name s.getters; setters = SMap.remove name s.setters; }) -let add_method ~static name loc fsig = map_sig ~static (fun s -> { +let add_method ~static name meth = map_sig ~static (fun s -> { s with fields = if static then SMap.remove name s.fields else s.fields; - methods = SMap.add name (Nel.one (loc, fsig)) s.methods; + methods = SMap.add name (Nel.one meth) s.methods; getters = SMap.remove name s.getters; setters = SMap.remove name s.setters; }) +let add_abstract ~static name meth = map_sig ~static (fun s -> { + s with + abstracts = SMap.add name meth s.abstracts; +}) + (* Appending a method builds a list of function signatures. This implements the bahvior of interfaces and declared classes, which interpret duplicate definitions as branches of a single overloaded method. *) -let append_method ~static name loc fsig = map_sig ~static (fun s -> { +let append_method ~static name meth = map_sig ~static (fun s -> { s with fields = if static then SMap.remove name s.fields else s.fields; methods = ( match SMap.get name s.methods with - | Some fsigs -> SMap.add name (Nel.cons (loc, fsig) fsigs) s.methods - | None -> SMap.add name (Nel.one (loc, fsig)) s.methods + | Some fsigs -> SMap.add name (Nel.cons meth fsigs) s.methods + | None -> SMap.add name (Nel.one meth) s.methods ); getters = SMap.remove name s.getters; setters = SMap.remove name s.setters; }) -let add_getter ~static name loc fsig = map_sig ~static (fun s -> { +let add_getter ~static name meth = map_sig ~static (fun s -> { s with fields = if static then SMap.remove name s.fields else s.fields; methods = SMap.remove name s.methods; - getters = SMap.add name (loc, fsig) s.getters; + getters = SMap.add name meth s.getters; }) -let add_setter ~static name loc fsig = map_sig ~static (fun s -> { +let add_setter ~static name meth = map_sig ~static (fun s -> { s with fields = if static then SMap.remove name s.fields else s.fields; methods = SMap.remove name s.methods; - setters = SMap.add name (loc, fsig) s.setters; + setters = SMap.add name meth s.setters; }) +let mask { fields; methods; getters; _ } = + let add_keys map = SMap.fold (fun k _ acc -> SSet.add k acc) map in + SSet.empty |> add_keys fields |> add_keys methods |> add_keys getters + +let abstracts { abstracts; _ } = + abstracts |> SMap.map (fun (_, _, fsig) -> Func_sig.reason_of_t fsig) + +let mk_abstract cx x loc func = + let fsig = Func_sig.convert cx x.tparams_map loc func in + Func_sig.replace_reason_const (RPropertyDef RAbstractMethodDef) fsig + let mk_method cx ~expr x loc func = Func_sig.mk cx x.tparams_map ~expr loc func -let mk_field cx loc ~polarity x reason typeAnnotation init = - loc, polarity, match init with +let mk_field cx x reason typeAnnotation = function | None -> Annot (Anno.mk_type_annotation cx x.tparams_map reason typeAnnotation) | Some expr -> Infer ( Func_sig.field_initializer cx x.tparams_map reason expr typeAnnotation) @@ -213,22 +238,22 @@ let iter_methods f s = SMap.iter (fun _ -> f) s.setters (* TODO? *) -let subst_field cx map (loc, polarity, field) = - loc, polarity, match field with - | Annot t -> Annot (Flow.subst cx map t) - | Infer fsig -> Infer (Func_sig.subst cx map fsig) - -let subst_sig cx map s = - let subst_func_sig (loc, sig_) = (loc, Func_sig.subst cx map sig_) in - { - reason = s.reason; - super = Flow.subst cx map s.super; - fields = SMap.map (subst_field cx map) s.fields; - private_fields = SMap.map (subst_field cx map) s.private_fields; - methods = SMap.map (Nel.map subst_func_sig) s.methods; - getters = SMap.map (subst_func_sig) s.getters; - setters = SMap.map (subst_func_sig) s.setters; - } +let subst_field cx map (fld, polarity) = + map_third (function + | Annot t -> Annot (Flow.subst cx map t) + | Infer fsig -> Infer (Func_sig.subst cx map fsig) + ) fld, polarity + +let subst_sig cx map s = { + reason = s.reason; + super = Flow.subst cx map s.super; + fields = SMap.map (subst_field cx map) s.fields; + private_fields = SMap.map (subst_field cx map) s.private_fields; + abstracts = SMap.map (map_third (Func_sig.subst cx map)) s.abstracts; + methods = SMap.map (Nel.map (map_third (Func_sig.subst cx map))) s.methods; + getters = SMap.map (map_third (Func_sig.subst cx map)) s.getters; + setters = SMap.map (map_third (Func_sig.subst cx map)) s.setters; +} let generate_tests cx f x = Flow.generate_tests cx x.instance.reason x.tparams (fun map -> f { @@ -237,60 +262,65 @@ let generate_tests cx f x = tparams = x.tparams; tparams_map = SMap.map (Flow.subst cx map) x.tparams_map; implements = List.map (Flow.subst cx map) x.implements; - constructor = List.map (fun (loc, sig_) -> loc, Func_sig.subst cx map sig_) x.constructor; + constructor = List.map (map_third (Func_sig.subst cx map)) x.constructor; static = subst_sig cx map x.static; instance = subst_sig cx map x.instance; }) -let to_field (loc, polarity, field) = - let t = match field with - | Annot t -> t - | Infer fsig -> Func_sig.gettertype fsig - in - Type.Field (loc, t, polarity) +let to_field (fld, polarity) = + let triple = map_third (function + | Annot t -> t + | Infer fsig -> Func_sig.gettertype fsig + ) fld in + Type.Field (triple, polarity) let elements cx ?constructor s = - let methods = + let open Type in + + let nonabstracts = (* If this is an overloaded method, create an intersection, attributed to the first declared function signature. If there is a single function signature for this method, simply return the method type. *) - SMap.map Type.(fun xs -> - match Nel.rev_map (fun (loc, x) -> loc, Func_sig.methodtype cx x) xs with + SMap.map (fun xs -> + match Nel.rev_map (map_third (Func_sig.methodtype cx)) xs with | x, [] -> x - | (loc0, t0), (_, t1)::ts -> - let ts = List.map (fun (_loc, t) -> t) ts in - loc0, DefT (reason_of_t t0, IntersectionT (InterRep.make t0 t1 ts)) + | (loc0, key_loc0, t0), (_loc1, _key_loc1, t1)::ts -> + let ts = List.map (fun (_loc, _key_loc, t) -> t) ts in + let reason = reason_of_t t0 in + loc0, key_loc0, DefT (reason, IntersectionT (InterRep.make t0 t1 ts)) ) s.methods in (* Re-add the constructor as a method. *) - let methods = match constructor with - | Some t -> SMap.add "constructor" t methods - | None -> methods + let nonabstracts = match constructor with + | Some t -> SMap.add "constructor" t nonabstracts + | None -> nonabstracts in - (* If there is a both a getter and a setter, then flow the setter type to - the getter. Otherwise just use the getter type or the setter type *) - let getters = SMap.map (fun (loc, t) -> loc, Func_sig.gettertype t) s.getters in - let setters = SMap.map (fun (loc, t) -> loc, Func_sig.settertype t) s.setters in + (* Sort getters and setters into property types. *) + let getters = SMap.map (map_third Func_sig.gettertype) s.getters in + let setters = SMap.map (map_third Func_sig.settertype) s.setters in let getters_and_setters = SMap.merge (fun _ getter setter -> match getter, setter with - | Some (loc1, t1), Some (loc2, t2) -> Some (Type.GetSet (loc1, t1, loc2, t2)) - | Some (loc, t), None -> Some (Type.Get (loc, t)) - | None, Some (loc, t) -> Some (Type.Set (loc, t)) + | Some get, Some set ->Some (GetSet (get, set)) + | Some get, None -> Some (Get get) + | None, Some set -> Some (Set set) | _ -> None ) getters setters in - let fields = SMap.map to_field s.fields in - (* Treat getters and setters as fields *) - let fields = SMap.union getters_and_setters fields in + let fields = SMap.union getters_and_setters (SMap.map to_field s.fields) in - let methods = SMap.map (fun (loc, t) -> Type.Method (loc, t)) methods in + let methods = + s.abstracts + |> SMap.map (map_third (Func_sig.methodtype cx)) + |> SMap.map (fun abstract -> Abstract abstract) + |> SMap.fold (fun x triple ms -> SMap.add x (Method triple) ms) nonabstracts + in (* Only un-initialized fields require annotations, so determine now * (syntactically) which fields have initializers *) - let initialized_field_names = SMap.fold (fun x (_, _, field) acc -> + let initialized_field_names = SMap.fold (fun x ((_, _, field), _) acc -> match field with | Annot _ -> acc | Infer _ -> SSet.add x acc @@ -324,15 +354,15 @@ let statictype cx s = let insttype cx ~initialized_static_field_names s = let constructor = - let ts = List.rev_map (fun (loc, t) -> loc, Func_sig.methodtype cx t) s.constructor in + let ts = List.rev_map (map_third (Func_sig.methodtype cx)) s.constructor in match ts with | [] -> None | [x] -> Some x - | (loc0, t0)::(_loc1, t1)::ts -> - let ts = List.map snd ts in + | (loc0, key_loc0, t0)::(_loc1, _key_loc1, t1)::ts -> + let ts = List.map (fun (_loc, _key_loc, t) -> t) ts in let open Type in let t = DefT (reason_of_t t0, IntersectionT (InterRep.make t0 t1 ts)) in - Some (loc0, t) + Some (loc0, key_loc0, t) in let inited_fields, fields, methods = elements cx ?constructor s.instance in { Type. @@ -425,10 +455,22 @@ let check_super cx def_reason x = flipped off for interface/declare class currently. *) let classtype cx ?(check_polarity=true) x = let this = thistype cx x in - let { structural; tparams; _ } = remove_this x in + let { structural; tparams; + instance = { reason; _ }; + _ + } = remove_this x in let open Type in (if check_polarity then Flow.check_polarity cx Positive this); - let t = if structural then class_type this else this_class_type this in + let t = if structural then nonabstract_class_type this else + let super = x.instance.super in + let masks = (mask x.static, mask x.instance) in + let local_abstracts = (abstracts x.static, abstracts x.instance) in + let reason = replace_reason (fun desc -> RAbstractsOf desc) reason in + let abstracts = Tvar.mk_where cx reason (fun tvar -> + Flow.flow cx (super, AccAbstractsT (reason, masks, local_abstracts, tvar)) + ) in + this_class_type this abstracts + in poly_type (Context.make_nominal cx) tparams t let mk_super cx tparams_map c targs = Type.( @@ -466,13 +508,13 @@ let mk_extends cx tparams_map ~expr = function let c = expr cx e in Explicit (mk_super cx tparams_map c targs) -let mk_mixins cx tparams_map (r, id, targs) = +let mk_mixin cx tparams_map (r, id, targs) = let i = let lookup_mode = Env.LookupMode.ForValue in Anno.convert_qualification ~lookup_mode cx "mixins" id in - let props_bag = Tvar.mk_derivable_where cx r (fun tvar -> - Flow.flow cx (i, Type.MixinT (r, tvar)) + let props_bag = Tvar.mk_derivable_where cx r Type.(fun tvar -> + Flow.flow cx (i, MixinT (unknown_use, r, tvar)) ) in mk_super cx tparams_map props_bag targs @@ -560,9 +602,11 @@ let mk cx _loc reason self ~expr = (* All classes have a static "name" property. *) let class_sig = + let name = "name" in let reason = replace_reason (fun desc -> RNameProperty desc) reason in - let t = Type.StrT.why reason in - add_field ~static:true "name" (None, Type.Neutral, Annot t) class_sig + let kind = Type.Property.Member (name, loc_of_reason reason) in + let fld = (kind, None, Annot (Type.StrT.why reason)) in + add_field ~static:true name fld Type.Neutral class_sig in (* NOTE: We used to mine field declarations from field assignments in a @@ -573,6 +617,17 @@ let mk cx _loc reason self ~expr = it. In the future, we could do it again, but only for private fields. *) List.fold_left Ast.Class.(fun c -> function + (* abstract instance and abstract static methods *) + | Body.AbstractMethod (loc, { + AbstractMethod.key = (id_loc, name); + value = (_, func); + static; + }) -> + + let fsig = mk_abstract cx c loc func in + let meth = (Type.Property.Explicit loc, Some id_loc, fsig) in + add_abstract ~static name meth c + (* instance and static methods *) | Body.Property (_, { Property.key = Ast.Expression.Object.Property.PrivateName _; @@ -599,14 +654,14 @@ let mk cx _loc reason self ~expr = | Get | Set -> Flow_js.add_output cx (Flow_error.EUnsafeGettersSetters loc) | _ -> ()); - let add = match kind with - | Method.Constructor -> add_constructor (Some id_loc) - | Method.Method -> add_method ~static name (Some id_loc) - | Method.Get -> add_getter ~static name (Some id_loc) - | Method.Set -> add_setter ~static name (Some id_loc) - in - let method_sig = mk_method cx ~expr c loc func in - add method_sig c + let fsig = mk_method cx ~expr c loc func in + let meth = (Type.Property.Explicit loc, Some id_loc, fsig) in + begin match kind with + | Method.Constructor -> add_constructor meth c + | Method.Method -> add_method ~static name meth c + | Method.Get -> add_getter ~static name meth c + | Method.Set -> add_setter ~static name meth c + end (* fields *) | Body.PrivateField(loc, { @@ -622,10 +677,13 @@ let mk cx _loc reason self ~expr = if value <> None then warn_or_ignore_class_properties cx ~static loc; - let reason = mk_reason (RProperty (Some name)) loc in + let fld = + let reason = mk_reason (RProperty (Some name)) loc in + let t = mk_field cx c reason typeAnnotation value in + (Type.Property.Explicit loc, Some id_loc, t) + in let polarity = Anno.polarity variance in - let field = mk_field cx (Some id_loc) ~polarity c reason typeAnnotation value in - add_private_field ~static name field c + add_private_field ~static name fld polarity c | Body.Property (loc, { Property.key = Ast.Expression.Object.Property.Identifier (id_loc, name); @@ -640,10 +698,13 @@ let mk cx _loc reason self ~expr = if value <> None then warn_or_ignore_class_properties cx ~static loc; - let reason = mk_reason (RProperty (Some name)) loc in + let fld = + let reason = mk_reason (RProperty (Some name)) loc in + let t = mk_field cx c reason typeAnnotation value in + (Type.Property.Explicit loc, Some id_loc, t) + in let polarity = Anno.polarity variance in - let field = mk_field cx (Some id_loc) ~polarity c reason typeAnnotation value in - add_field ~static name field c + add_field ~static name fld polarity c (* literal LHS *) | Body.Method (loc, { @@ -690,19 +751,22 @@ let add_interface_properties cx properties s = List.fold_left Ast.Type.Object.(fun x -> function | CallProperty (loc, { CallProperty.value = (_, func); static }) -> let fsig = Func_sig.convert cx tparams_map loc func in - append_method ~static "$call" None fsig x + let meth = (Type.Property.Explicit loc, None, fsig) in + append_method ~static "$call" meth x | Indexer (loc, { Indexer.static; _ }) when mem_field ~static "$key" x -> Flow.add_output cx Flow_error.(EUnsupportedSyntax (loc, MultipleIndexers)); x - | Indexer (_, { Indexer.key; value; static; variance; _ }) -> + | Indexer (loc, { Indexer.key; value; static; variance; _ }) -> let k = Anno.convert cx tparams_map key in let v = Anno.convert cx tparams_map value in let polarity = Anno.polarity variance in + let kind = Type.Property.Explicit loc in x - |> add_field ~static "$key" (None, polarity, Annot k) - |> add_field ~static "$value" (None, polarity, Annot v) - | Property (loc, { Property.key; value; static; _method; optional; variance; }) -> + |> add_field ~static "$key" (kind, None, Annot k) polarity + |> add_field ~static "$value" (kind, None, Annot v) polarity + | Property (loc, { Property. + key; value; optional; abstract; static; _method; variance; }) -> if optional && _method then Flow.add_output cx Flow_error.(EInternal (loc, OptionalMethod)); let polarity = Anno.polarity variance in @@ -714,12 +778,17 @@ let add_interface_properties cx properties s = x | true, Property.Identifier (id_loc, name), Ast.Type.Object.Property.Init (_, Ast.Type.Function func) -> - let fsig = Func_sig.convert cx tparams_map loc func in - let append_method = match static, name with - | false, "constructor" -> append_constructor (Some id_loc) - | _ -> append_method ~static name (Some id_loc) + let fsig = + if abstract + then mk_abstract cx x loc func + else Func_sig.convert cx tparams_map loc func in - append_method fsig x + let meth = (Type.Property.Explicit loc, Some id_loc, fsig) in + begin match abstract, static, name with + | true, _, _ -> add_abstract ~static name meth x + | false, false, "constructor" -> append_constructor meth x + | _ -> append_method ~static name meth x + end | true, Property.Identifier _, _ -> Flow.add_output cx @@ -728,24 +797,29 @@ let add_interface_properties cx properties s = | false, Property.Identifier (id_loc, name), Ast.Type.Object.Property.Init value -> + assert(not abstract); let t = Anno.convert cx tparams_map value in let t = if optional then Type.optional t else t in - add_field ~static name (Some id_loc, polarity, Annot t) x + let fld = (Type.Property.Explicit loc, Some id_loc, Annot t) in + add_field ~static name fld polarity x (* unsafe getter property *) | _, Property.Identifier (id_loc, name), - Ast.Type.Object.Property.Get (_, func) -> + Ast.Type.Object.Property.Get (_, func) -> + assert(not abstract); Flow_js.add_output cx (Flow_error.EUnsafeGettersSetters loc); let fsig = Func_sig.convert cx tparams_map loc func in - add_getter ~static name (Some id_loc) fsig x + let meth = (Type.Property.Explicit loc, Some id_loc, fsig) in + add_getter ~static name meth x (* unsafe setter property *) | _, Property.Identifier (id_loc, name), - Ast.Type.Object.Property.Set (_, func) -> + Ast.Type.Object.Property.Set (_, func) -> + assert(not abstract); Flow_js.add_output cx (Flow_error.EUnsafeGettersSetters loc); let fsig = Func_sig.convert cx tparams_map loc func in - add_setter ~static name (Some id_loc) fsig x - + let meth = (Type.Property.Explicit loc, Some id_loc, fsig) in + add_setter ~static name meth x ) | SpreadProperty (loc, _) -> @@ -778,9 +852,11 @@ let of_interface cx reason { Ast.Statement.Interface. in let iface_sig = + let name = "name" in let reason = replace_reason (fun desc -> RNameProperty desc) reason in - let t = Type.StrT.why reason in - add_field ~static:true "name" (None, Type.Neutral, Annot t) iface_sig + let kind = Type.Property.Member (name, loc_of_reason reason) in + let fld = (kind, None, Annot (Type.StrT.why reason)) in + add_field ~static:true name fld Type.Neutral iface_sig in let iface_sig = add_interface_properties cx properties iface_sig in @@ -807,32 +883,37 @@ let of_declare_class cx reason { Ast.Statement.DeclareClass. let id = Context.make_nominal cx in let extends = match extends with - | Some (_, {Ast.Type.Generic.id; typeParameters}) -> + | Some (loc, {Ast.Type.Generic.id; typeParameters}) -> let lookup_mode = Env.LookupMode.ForValue in let i = Anno.convert_qualification ~lookup_mode cx "mixins" id in - Some (mk_super cx tparams_map i typeParameters) - | None -> - None + let super = mk_super cx tparams_map i typeParameters in + if mixins <> [] then Type.( + let super = Flow.reposition cx loc super in + let kind = NonabstractClass in + Flow.flow cx (super, AssertNonabstractT (unknown_use, reason, kind)) + ); + Explicit super + | None -> Implicit { null = is_object_builtin_libdef ident } in let mixins = mixins |> extract_mixins cx - |> List.map (mk_mixins cx tparams_map) - in - let super = - let extends = match extends with - | None -> Implicit { null = is_object_builtin_libdef ident } - | Some t -> Explicit t - in - Class { extends; mixins; implements = [] } + |> List.map (mk_mixin cx tparams_map) in + mixins |> List.iter Type.(fun mixin -> + let kind = NonabstractClass in + Flow.flow cx (mixin, AssertNonabstractT (unknown_use, reason, kind)) + ); + let super = Class { extends; mixins; implements = [] } in empty id reason tparams tparams_map super in let iface_sig = + let name = "name" in let reason = replace_reason (fun desc -> RNameProperty desc) reason in - let t = Type.StrT.why reason in - add_field ~static:true "name" (None, Type.Neutral, Annot t) iface_sig + let kind = Type.Property.Member (name, loc_of_reason reason) in + let fld = (kind, None, Annot (Type.StrT.why reason)) in + add_field ~static:true name fld Type.Neutral iface_sig in let iface_sig = add_interface_properties cx properties iface_sig in @@ -863,7 +944,7 @@ let toplevels cx ~decls ~stmts ~expr x = ignore (Abnormal.swap_saved Abnormal.Throw save_throw) in - let field config this super _name (_, _, value) = + let field config this super _name ((_, _, value), _) = match config, value with | Options.ESPROPOSAL_IGNORE, _ -> () | _, Annot _ -> () @@ -871,7 +952,7 @@ let toplevels cx ~decls ~stmts ~expr x = in let this = SMap.find_unsafe "this" x.tparams_map in - let static = Type.class_type this in + let static = Type.nonabstract_class_type this in (* Bind private fields to the environment *) let to_prop_map = fun x -> Context.make_property_map cx (SMap.map to_field x) in @@ -881,7 +962,7 @@ let toplevels cx ~decls ~stmts ~expr x = x |> with_sig ~static:true (fun s -> (* process static methods and fields *) let this, super = new_entry static, new_entry s.super in - iter_methods (fun (_loc, f) -> method_ this super f) s; + iter_methods (fun (_, _, fsig) -> method_ this super fsig) s; let config = Context.esproposal_class_static_fields cx in SMap.iter (field config this super) s.fields; SMap.iter (field config this super) s.private_fields @@ -898,7 +979,7 @@ let toplevels cx ~decls ~stmts ~expr x = locals, e.g., so it cannot be used in general to track definite assignments. *) let derived_ctor = Type.(match s.super with - | DefT (_, ClassT (ObjProtoT _)) -> false + | DefT (_, ClassT (ObjProtoT _, _)) -> false | ObjProtoT _ -> false | _ -> true ) in @@ -913,13 +994,13 @@ let toplevels cx ~decls ~stmts ~expr x = new_entry t in let this, super = new_entry this, new_entry s.super in - x.constructor |> List.iter (fun (_, fsig) -> method_ this super fsig) + x.constructor |> List.iter (fun (_, _, fsig) -> method_ this super fsig) end; (* process instance methods and fields *) begin let this, super = new_entry this, new_entry s.super in - iter_methods (fun (_, msig) -> method_ this super msig) s; + iter_methods (fun (_, _, fsig) -> method_ this super fsig) s; let config = Context.esproposal_class_instance_fields cx in SMap.iter (field config this super) s.fields; SMap.iter (field config this super) s.private_fields; diff --git a/src/typing/class_sig.mli b/src/typing/class_sig.mli index 00cf4d43916..934260ea0f1 100644 --- a/src/typing/class_sig.mli +++ b/src/typing/class_sig.mli @@ -2,8 +2,11 @@ type t -type field = Loc.t option * Type.polarity * field' -and field' = Annot of Type.t | Infer of Func_sig.t +type field = fld * Type.polarity +and fld = Type.Property.kind * Loc.t option * field_t +and field_t = Annot of Type.t | Infer of Func_sig.t + +type meth = Type.Property.kind * Loc.t option * Func_sig.t type super = | Interface of { @@ -36,37 +39,37 @@ val empty: Overwrites any existing constructor. This implements the behavior of classes, which permit duplicate definitions where latter definitions overwrite former ones. *) -val add_constructor: Loc.t option -> Func_sig.t -> t -> t +val add_constructor: meth -> t -> t (** Add constructor override to signature. Does not overwrite existing constructors. This implements the behavior of interfaces, which interpret duplicate definitions as branches of a single overloaded constructor. *) -val append_constructor: Loc.t option -> Func_sig.t -> t -> t +val append_constructor: meth -> t -> t (** Add field to signature. *) -val add_field: static:bool -> string -> field -> t -> t +val add_field: static:bool -> string -> fld -> Type.polarity -> t -> t (** Add method to signature. Overwrites any existing synonymous method. This implements the behavior of classes, which permit duplicate definitions where latter definitions overwrite former ones. *) -val add_method: static:bool -> string -> Loc.t option -> Func_sig.t -> t -> t +val add_method: static:bool -> string -> meth -> t -> t (** Add method override to signature. Does not overwrite existing synonymous methods. This implements the behavior of interfaces, which interpret duplicate definitions as branches of a single overloaded method. *) -val append_method: static:bool -> string -> Loc.t option -> Func_sig.t -> t -> t +val append_method: static:bool -> string -> meth -> t -> t (** Add getter to signature. *) -val add_getter: static:bool -> string -> Loc.t option -> Func_sig.t -> t -> t +val add_getter: static:bool -> string -> meth -> t -> t (** Add setter to signature. *) -val add_setter: static:bool -> string -> Loc.t option -> Func_sig.t -> t -> t +val add_setter: static:bool -> string -> meth -> t -> t (** Create signature from class AST. *) val mk: Context.t -> diff --git a/src/typing/codegen.ml b/src/typing/codegen.ml index 24f87c45059..61d8a8f19c4 100644 --- a/src/typing/codegen.ml +++ b/src/typing/codegen.ml @@ -119,9 +119,9 @@ let gen_builtin_class_type t env = Type.( let builtin_t = Flow_js.get_builtin env.flow_cx builtin_name reason in let builtin_classid = match resolve_type builtin_t env with - | ThisClassT(_, DefT (_, InstanceT (_, _, _, {class_id; _;}))) -> + | ThisClassT(_, DefT (_, InstanceT (_, _, _, {class_id; _;})), _) -> class_id - | DefT (_, PolyT(_, ThisClassT(_, DefT (_, InstanceT(_, _, _, {class_id; _;}))), _)) -> + | DefT (_, PolyT(_, ThisClassT(_, DefT (_, InstanceT(_, _, _, {class_id; _;})), _), _)) -> class_id | builtin_t -> failwith (spf "Unexpected global type: %s" (string_of_ctor builtin_t)) in @@ -184,7 +184,7 @@ let rec gen_type t env = Type.( | DefT (_, BoolT None) -> add_str "boolean" env | BoundT {name; _;} -> add_str name env - | DefT (_, ClassT t) -> + | DefT (_, ClassT (t, _)) -> add_str "Class<" env |> gen_type t |> add_str ">" @@ -272,7 +272,7 @@ let rec gen_type t env = Type.( (* Generate potential dict entry *) let env = match dict_t with - | Some {dict_name; key; value; dict_polarity} -> + | Some {dict_name; dict_kind = _; key; value; dict_polarity} -> let key_name = ( match dict_name with | Some n -> n @@ -307,7 +307,7 @@ let rec gen_type t env = Type.( (* TODO: Consider polarity and print the literal type when appropriate *) add_str "string" env | DefT (_, StrT (Truthy|AnyLiteral)) -> add_str "string" env - | ThisClassT (_, t) -> gen_type t env + | ThisClassT (_, t, _) -> gen_type t env | ThisTypeAppT (_, t, _, Some ts) -> add_applied_tparams ts env |> gen_type t | ThisTypeAppT (_, t, _, None) -> gen_type t env | DefT (_, TypeAppT (t, ts)) -> add_applied_tparams ts env |> gen_type t @@ -324,6 +324,7 @@ let rec gen_type t env = Type.( * handling for these types depening on the needs of the API user * (i.e. raise, etc). *) + | AbstractsT _ | InternalT (ChoiceKitT _) | TypeDestructorTriggerT _ | DefT (_, EmptyT) @@ -337,7 +338,7 @@ let rec gen_type t env = Type.( -> add_str (spf "mixed /* UNEXPECTED TYPE: %s */" (string_of_ctor t)) env ) -and gen_prop k p env = +and gen_prop ?(static=false) k p env = let open Type in let gen_getter k t env = @@ -369,8 +370,14 @@ and gen_prop k p env = | _ -> add_str (spf "mixed /* UNEXPECTED TYPE: %s */" (string_of_ctor t)) env in + let env = + match p with + | Abstract _ -> add_str "abstract " env + | _ -> env + in + let env = gen_if static (add_str "static ") env in match p with - | Field (_, t, polarity) -> + | Field ((_, _, t), polarity) -> let sigil = Polarity.sigil polarity in let (sep, t) = match resolve_type t env with @@ -381,11 +388,12 @@ and gen_prop k p env = |> add_str k |> add_str sep |> gen_type t - | Get (_, t) -> gen_getter k t env - | Set (_, t) -> gen_setter k t env - | GetSet (_, t1, _, t2) -> + | Get (_, _, t) -> gen_getter k t env + | Set (_, _, t) -> gen_setter k t env + | GetSet ((_, _, t1), (_, _, t2)) -> gen_getter k t1 env |> gen_setter k t2 - | Method (_, t) -> gen_method k t env + | Method (_, _, t) + | Abstract (_, _, t) -> gen_method k t env and gen_func_params params rest_param env = let params_rev = List.fold_left (fun acc (name, t) -> diff --git a/src/typing/debug_js.ml b/src/typing/debug_js.ml index d557606cda1..6b9db9ee07b 100644 --- a/src/typing/debug_js.ml +++ b/src/typing/debug_js.ml @@ -152,8 +152,9 @@ and _json_of_t_impl json_cx t = Hh_json.( "chars", JSON_String (String_utils.CharSet.to_string chars); ] - | DefT (_, ClassT t) -> [ - "type", _json_of_t json_cx t + | DefT (_, ClassT (t, abstracts)) -> [ + "type", _json_of_t json_cx t; + "abstracts", _json_of_t json_cx abstracts ] | DefT (_, InstanceT (static, super, implements, instance)) -> [ @@ -188,8 +189,9 @@ and _json_of_t_impl json_cx t = Hh_json.( "type", _json_of_t json_cx t ] - | ThisClassT (_, t) -> [ - "type", _json_of_t json_cx t + | ThisClassT (_, t, abstracts) -> [ + "type", _json_of_t json_cx t; + "abstracts", _json_of_t json_cx abstracts ] | ThisTypeAppT (_, t, this, targs_opt) -> ( @@ -201,6 +203,15 @@ and _json_of_t_impl json_cx t = Hh_json.( "type", _json_of_t json_cx t ] + | AbstractsT (_, (static_abstracts, abstracts)) -> + let static_abstracts = SMap.keys static_abstracts in + let abstracts = SMap.keys abstracts in + let intern s = JSON_String s in + [ + "staticAbstracts", JSON_Array (List.map intern static_abstracts); + "abstracts", JSON_Array (List.map intern abstracts) + ] + | BoundT tparam -> [ "typeParam", json_of_typeparam json_cx tparam ] @@ -465,6 +476,18 @@ and _json_of_use_t_impl json_cx t = Hh_json.( "type", _json_of_t json_cx t ] + | AssertNonabstractT (_, _, nonabstract) -> + (match nonabstract with + | NonabstractMember (static, name) -> [ + "target", JSON_String "Member"; + "static", JSON_Bool static; + "name", JSON_String name + ] + | NonabstractClass -> [ + "target", JSON_String "Class" + ] + ) + | GetProtoT (_, t) | SetProtoT (_, t) -> [ "type", _json_of_t json_cx t @@ -488,7 +511,7 @@ and _json_of_use_t_impl json_cx t = Hh_json.( "instance", _json_of_t json_cx t; ] - | MixinT (_, t) -> [ + | MixinT (_, _, t) -> [ "type", _json_of_t json_cx t ] @@ -496,6 +519,30 @@ and _json_of_use_t_impl json_cx t = Hh_json.( "type", _json_of_t json_cx t ] + | AccAbstractsT (_, masks, local_abstracts, t) -> + let intern s = JSON_String s in + let json_of_mask mask = JSON_Array (List.map intern (SSet.elements mask)) in + let json_of_la la = JSON_Array (List.map intern (SMap.keys la)) in + let masks = + let (static, nonstatic) = masks in + JSON_Object [ + "static", json_of_mask static; + "nonstatic", json_of_mask nonstatic + ] + in + let local_abstracts = + let (static, nonstatic) = local_abstracts in + JSON_Object [ + "static", json_of_la static; + "nonstatic", json_of_la nonstatic; + ] + in + [ + "type", _json_of_t json_cx t; + "masks", masks; + "localAbstracts", local_abstracts + ] + | AdderT (_, _, l, r) -> [ "leftType", _json_of_t json_cx l; "rightType", _json_of_t json_cx r @@ -1214,23 +1261,26 @@ and json_of_prop_binding_impl json_cx (name, p) = Hh_json.( and json_of_prop json_cx = check_depth json_of_prop_impl json_cx and json_of_prop_impl json_cx p = Hh_json.( JSON_Object (match p with - | Field (_loc, t, polarity) -> [ + | Field ((_loc, _key_loc, t), polarity) -> [ "field", _json_of_t json_cx t; "polarity", json_of_polarity json_cx polarity ] - | Get (_loc, t) -> [ + | Get (_loc, _key_loc, t) -> [ "getter", _json_of_t json_cx t; ] - | Set (_loc, t) -> [ + | Set (_loc, _key_loc, t) -> [ "setter", _json_of_t json_cx t; ] - | GetSet (_loc1, t1, _loc2, t2) -> [ + | GetSet ((_loc1, _key_loc1, t1), (_loc2, _key_loc2, t2)) -> [ "getter", _json_of_t json_cx t1; "setter", _json_of_t json_cx t2; ] - | Method (_loc, t) -> [ + | Method (_loc, _key_loc, t) -> [ "method", _json_of_t json_cx t; ] + | Abstract (_loc, _key_loc, t) -> [ + "abstractMethod", _json_of_t json_cx t; + ] )) and json_of_type_binding json_cx = check_depth json_of_type_binding_impl json_cx @@ -1686,7 +1736,7 @@ and dump_t_ (depth, tvars) cx t = (kid c) (String.concat "; " (List.map (fun tp -> tp.name) tps)) id) t - | ThisClassT (_, inst) -> p ~extra:(kid inst) t + | ThisClassT (_, inst, _) -> p ~extra:(kid inst) t | BoundT param -> p ~extra:param.name t | ExistsT _ -> p t | DefT (_, ObjT { props_tmap; _ }) -> p t @@ -1701,7 +1751,7 @@ and dump_t_ (depth, tvars) cx t = ~extra:(spf "ReadOnlyArray %s" (kid elemt)) t | DefT (_, ArrT EmptyAT) -> p ~extra:("EmptyArray") t | DefT (_, CharSetT chars) -> p ~extra:(spf "<%S>" (String_utils.CharSet.to_string chars)) t - | DefT (_, ClassT inst) -> p ~extra:(kid inst) t + | DefT (_, ClassT (inst, _)) -> p ~extra:(kid inst) t | DefT (_, InstanceT (_, _, _, { class_id; _ })) -> p ~extra:(spf "#%d" class_id) t | DefT (_, TypeT arg) -> p ~extra:(kid arg) t | AnnotT ((_, id), use_desc) -> @@ -1719,6 +1769,7 @@ and dump_t_ (depth, tvars) cx t = (String.concat "; " (List.map kid args)) | None -> spf "%s, %s" (kid base) (kid this) end t + | AbstractsT _ -> p t | ExactT (_, arg) -> p ~extra:(kid arg) t | DefT (_, MaybeT arg) -> p ~extra:(kid arg) t | DefT (_, IntersectionT rep) -> p ~extra:(spf "[%s]" @@ -1832,8 +1883,21 @@ and dump_use_t_ (depth, tvars) cx t = | ResolveObject -> "ResolveObject" | ResolveDict (_, todo, acc) -> spf "ResolveDict (%s, %s)" (props todo) (resolved_object acc) - | ResolveProp (k, todo, acc) -> - spf "ResolveProp (%s, %s, %s)" k (props todo) (resolved_object acc) + | ResolveProp (k, kind, key_loc, todo, acc) -> + spf "ResolveProp (%s, %s, %s, %s, %s)" + k + (match kind with + | Property.Member (name, loc) -> + spf "Member (%s, %s)" name (string_of_loc loc) + | Property.Explicit loc -> + spf "Explicit (%s)" (string_of_loc loc) + | Property.Custom (msg, loc) -> + spf "Custom (%s, %s)" msg (string_of_loc loc)) + (key_loc |> (function + | Some l -> "Some " ^ (string_of_loc l) + | None -> "None")) + (props todo) + (resolved_object acc) in let simplify_prop_type = SimplifyPropType.(function | ArrayOf -> "ArrayOf" @@ -1885,7 +1949,7 @@ and dump_use_t_ (depth, tvars) cx t = | Some {dict_polarity=p; _} -> [(Polarity.sigil p)^"[]"] | None -> [] in - let xs = SMap.fold (fun k (t,_) xs -> + let xs = SMap.fold (fun k (_,t,_) xs -> let opt = match t with DefT (_, OptionalT _) -> "?" | _ -> "" in (k^opt)::xs ) props xs in @@ -1968,6 +2032,7 @@ and dump_use_t_ (depth, tvars) cx t = (dump_reason cx r) id | UseT (use_op, t) -> spf "UseT (%s, %s)" (string_of_use_op use_op) (kid t) + | AccAbstractsT (_, _, _, arg) -> p ~extra:(kid arg) t | AdderT (_, _, x, y) -> p ~extra:(spf "%s, %s" (kid x) (kid y)) t | AndT (_, x, y) -> p ~extra:(spf "%s, %s" (kid x) (kid y)) t | ArrRestT (use_op, _, _, _) -> p ~extra:(string_of_use_op use_op) t @@ -1976,6 +2041,7 @@ and dump_use_t_ (depth, tvars) cx t = | AssertBinaryInRHST _ -> p t | AssertForInRHST _ -> p t | AssertImportIsValueT _ -> p t + | AssertNonabstractT _ -> p t | AssertRestParamT _ -> p t | BecomeT (_, arg) -> p ~extra:(kid arg) t | BindT _ -> p t @@ -2041,7 +2107,7 @@ and dump_use_t_ (depth, tvars) cx t = | MakeExactT _ -> p t | MapTypeT _ -> p t | MethodT (_, _, _, prop, _, _) -> p ~extra:(spf "(%s)" (propref prop)) t - | MixinT (_, arg) -> p ~extra:(kid arg) t + | MixinT (_, _, arg) -> p ~extra:(kid arg) t | NotT (_, arg) -> p ~extra:(kid arg) t | ObjAssignToT (_, arg1, arg2, _) -> p t ~extra:(spf "%s, %s" (kid arg1) (kid arg2)) @@ -2157,16 +2223,18 @@ and dump_prop ?(depth=3) cx p = and dump_prop_ (depth, tvars) cx p = let kid t = dump_t_ (depth-1, tvars) cx t in match p with - | Field (_loc, t, polarity) -> + | Field ((_loc, _key_loc, t), polarity) -> spf "Field (%s) %s" (string_of_polarity polarity) (kid t) - | Get (_loc, t) -> + | Get (_loc, _key_loc, t) -> spf "Get %s" (kid t) - | Set (_loc, t) -> + | Set (_loc, _key_loc, t) -> spf "Set %s" (kid t) - | GetSet (_loc1, t1, _loc2, t2) -> + | GetSet ((_loc1, _key_loc1, t1), (_loc2, _key_loc2, t2)) -> spf "Get %s Set %s" (kid t1) (kid t2) - | Method (_loc, t) -> + | Method (_loc, _key_loc, t) -> spf "Method %s" (kid t) + | Abstract (_loc, _key_loc, t) -> + spf "Abstract %s" (kid t) (*****************************************************) @@ -2713,3 +2781,33 @@ let dump_flow_error = spf "EDeprecatedDeclareExports (%s)" (string_of_loc loc) | EInvalidPrototype reason -> spf "EInvalidPrototype (%s)" (dump_reason cx reason) + | EUnimplementedAbstracts { + use_op; reason; reason_op; abstracts; static_abstracts + } -> + let abstracts = List.map (dump_reason cx) abstracts in + let static_abstracts = List.map (dump_reason cx) static_abstracts in + spf "EUnimplementedAbstracts { %s; %s; %s; %s; %s }" + (spf "use_op = %s" (string_of_use_op use_op)) + (spf "reason = %s" (dump_reason cx reason)) + (spf "reason_op = %s" (dump_reason cx reason_op)) + (spf "abstracts = [%s]" (String.concat "; " abstracts)) + (spf "static_abstracts = [%s]" (String.concat "; " static_abstracts)) + | EUnimplementedAbstract { use_op; reason; reason_op; static; name } -> + spf "EUnimplementedAbstracts { %s; %s; %s; %s; %s }" + (spf "use_op = %s" (string_of_use_op use_op)) + (spf "reason = %s" (dump_reason cx reason)) + (spf "reason_op = %s" (dump_reason cx reason_op)) + (spf "static = %b" static) + (spf "name = %s" name) + | EAbstractMask { nonabstract; abstract } -> + spf "EAbstractMask { nonabstract = %s; abstract = %s }" + (dump_reason cx nonabstract) + (dump_reason cx abstract) + | EAbstractSet { abstract; setter } -> + spf "EAbstractSet { abstract = %s; setter = %s }" + (dump_reason cx abstract) + (dump_reason cx setter) + | EIllegalMixin { reason; reason_op } -> + spf "EIllegalMixin { reason = %s; reason_op = %s }" + (dump_reason cx reason) + (dump_reason cx reason_op) diff --git a/src/typing/flow_error.ml b/src/typing/flow_error.ml index 05b6f6cffe1..04d1adb9bac 100644 --- a/src/typing/flow_error.ml +++ b/src/typing/flow_error.ml @@ -167,6 +167,32 @@ type error_message = } | EInvalidPrototype of reason | EDeprecatedDeclareExports of Loc.t + | EUnimplementedAbstracts of { + use_op: use_op; + reason: reason; + reason_op: reason; + static_abstracts: reason list; + abstracts: reason list + } + | EUnimplementedAbstract of { + use_op: use_op; + reason: reason; + reason_op: reason; + static: bool; + name: string + } + | EAbstractMask of { + nonabstract: reason; + abstract: reason + } + | EAbstractSet of { + abstract: reason; + setter: reason + } + | EIllegalMixin of { + reason: reason; + reason_op: reason + } and binding_error = | ENameAlreadyBound @@ -293,6 +319,10 @@ let util_use_op_of_msg nope util = function | EIncompatibleWithUseOp (rl, ru, op) -> util op (fun op -> EIncompatibleWithUseOp (rl, ru, op)) | EReactKit (rs, t, op) -> util op (fun op -> EReactKit (rs, t, op)) | EFunctionCallExtraArg (rl, ru, n, op) -> util op (fun op -> EFunctionCallExtraArg (rl, ru, n, op)) +| EUnimplementedAbstracts {use_op; reason; reason_op; static_abstracts; abstracts} -> + util use_op (fun use_op -> EUnimplementedAbstracts {use_op; reason; reason_op; static_abstracts; abstracts}) +| EUnimplementedAbstract {use_op; reason; reason_op; static; name} -> + util use_op (fun use_op -> EUnimplementedAbstract {use_op; reason; reason_op; static; name}) | EIncompatible {lower=_; upper=_; extras=_} | EIncompatibleDefs {reason_lower=_; reason_upper=_; extras=_} | EIncompatibleGetProp {reason_prop=_; reason_obj=_; special=_} @@ -380,6 +410,9 @@ let util_use_op_of_msg nope util = function | ESketchyNullLint {kind=_; loc=_; null_loc=_; falsy_loc=_} | EInvalidPrototype (_) | EDeprecatedDeclareExports (_) +| EAbstractMask {nonabstract=_; abstract=_} +| EAbstractSet {abstract=_; setter=_} +| EIllegalMixin {reason=_; reason_op=_} -> nope (* Rank scores for signals of different strength on an x^2 scale so that greater @@ -1782,3 +1815,41 @@ let rec error_of_msg ~trace_reasons ~source_file = | EInvalidPrototype reason -> mk_error ~trace_infos [mk_info reason [ "Invalid prototype. Expected an object or null."]] + | EUnimplementedAbstracts { + use_op; reason; reason_op; static_abstracts; abstracts + } -> + let abstracts = + (* Sort abstract reasons by loc. *) + let add map reason = LocMap.add (loc_of_reason reason) reason map in + List.fold_left add LocMap.empty (static_abstracts@abstracts) + |> LocMap.bindings + |> List.map snd + |> List.map info_of_reason + in + let extra = [ + InfoLeaf ( + (Loc.none, ["Abstract(s):"])::abstracts + ) + ] in + let force = true in + let reasons = (reason_op, reason) in + let msg = "Unimplemented abstract(s) found in" in + let extra, msgs = unwrap_use_ops ~force (reasons, extra, msg) use_op in + typecheck_error_with_core_infos ~extra msgs + | EUnimplementedAbstract { use_op; reason; reason_op; static; name } -> + let msg = if static + then spf "Unimplemented abstract static `%s` found in" name + else spf "Unimplemented abstract `%s` found in" name + in + let reasons = (reason_op, reason) in + let extra, msgs = unwrap_use_ops (reasons, [], msg) use_op in + typecheck_error_with_core_infos ~extra msgs + | EAbstractMask { nonabstract; abstract } -> + let msg = "Cannot mask non-abstract" in + typecheck_error msg (abstract, nonabstract) + | EAbstractSet { abstract; setter } -> + let msg = "A setter without a getter cannot implement" in + typecheck_error msg (setter, abstract) + | EIllegalMixin { reason; reason_op } -> + let msg = "Illegal mixin" in + typecheck_error msg (reason_op, reason) diff --git a/src/typing/flow_js.ml b/src/typing/flow_js.ml index 3082c6da152..fdf036326af 100644 --- a/src/typing/flow_js.ml +++ b/src/typing/flow_js.ml @@ -303,7 +303,8 @@ let rec merge_type cx = * sufficient. *) | Some _, None | None, Some _ -> Some (o1.flags.exact || o2.flags.exact) (* Covariant fields can be merged. *) - | Some (Field (_, _, Positive)), Some (Field (_, _, Positive)) -> Some true + | Some (Field (_, Positive)), Some (Field (_, Positive)) -> + Some true (* Getters are covariant and thus can be merged. *) | Some (Get _), Some (Get _) -> Some true (* Anything else is can't be merged. *) @@ -320,6 +321,7 @@ let rec merge_type cx = (* TODO: How to merge indexer names? *) Some (Some { dict_name = None; + dict_kind = Property.Explicit Loc.none; key = create_intersection (InterRep.make k1 k2 []); value = merge_type cx (v1, v2); dict_polarity = Positive; @@ -1044,11 +1046,16 @@ module ResolvableTypeJob = struct | AnyWithLowerBoundT t | ExactT (_, t) | DefT (_, TypeT t) - | DefT (_, ClassT t) - | ThisClassT (_, t) -> collect_of_type ?log_unresolved cx reason acc t + | DefT (_, ClassT (t, abstracts_t)) + | ThisClassT (_, t, abstracts_t) + -> + let acc = collect_of_type ?log_unresolved cx reason acc t in + let acc = collect_of_type ?log_unresolved cx reason acc abstracts_t in + acc + | KeysT (_, t) -> collect_of_type ?log_unresolved cx reason acc t @@ -1091,6 +1098,7 @@ module ResolvableTypeJob = struct | NullProtoT _ | ObjProtoT _ | CustomFunT (_, _) + | AbstractsT (_, _) | ExistsT _ | OpenPredT _ @@ -2006,7 +2014,9 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = let proto = ObjProtoT reason in let exports_tmap = Context.find_exports cx exports.exports_tmap in (* TODO this Field should probably have a location *) - let props = SMap.map (fun t -> Field (None, t, Neutral)) exports_tmap in + let props = SMap.map (fun t -> + Field ((Property.Explicit (loc_of_t t), None, t), Neutral) + ) exports_tmap in Obj_type.mk_with_proto cx reason ~sealed:true ~frozen:true ~props proto ) in @@ -2017,19 +2027,22 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = check_nonstrict_import cx trace is_strict reason; let exports_tmap = Context.find_exports cx exports.exports_tmap in (* TODO this Field should probably have a location *) - let props = SMap.map (fun t -> Field (None, t, Neutral)) exports_tmap in + let props = SMap.map (fun t -> + Field ((Property.Explicit (loc_of_t t), None, t), Neutral) + ) exports_tmap in let props = match exports.cjs_export with | Some t -> (* TODO this Field should probably have a location *) - let p = Field (None, t, Neutral) in + let p = Field ((Property.Explicit (loc_of_t t), None, t), Neutral) in SMap.add "default" p props | None -> props in let dict = if exports.has_every_named_export then Some { + dict_name = None; + dict_kind = Property.Member ("[string]", loc_of_reason reason); key = StrT.why reason; value = AnyT.why reason; - dict_name = None; dict_polarity = Neutral; } else None in @@ -2534,6 +2547,81 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = | _, UseT (_, AnyWithUpperBoundT t) -> rec_flow_t cx trace (l, t) + (*************) + (* Abstracts *) + (*************) + + | ThisTypeAppT (reason, cls, _, _), AssertNonabstractT _ -> + rec_flow cx trace (ReposT (reason, cls), u) + + | ThisTypeAppT (_, cls, _, _), AccAbstractsT _ -> + rec_flow cx trace (cls, u) + + | ThisClassT (_, _, super_abstracts), AccAbstractsT _ -> + rec_flow cx trace (super_abstracts, u) + + | AbstractsT (_, super_abstracts), + AccAbstractsT (reason, masks, local_abstracts, t) -> + let extend super mask local = SMap.union local ( + SMap.filter (fun name _ -> not (SSet.mem name mask)) super + ) in + let abstracts = + extend (fst super_abstracts) (fst masks) (fst local_abstracts), + extend (snd super_abstracts) (snd masks) (snd local_abstracts) + in + let use_op = unknown_use in + rec_unify cx trace ~use_op (AbstractsT (reason, abstracts)) t + + | _, AccAbstractsT (reason, _, local_abstracts, t) -> + let use_op = unknown_use in + rec_unify cx trace ~use_op (AbstractsT (reason, local_abstracts)) t + + | ThisClassT (reason, _, abstracts), AssertNonabstractT _ + | DefT (reason, ClassT (_, abstracts)), AssertNonabstractT _ -> + rec_flow cx trace (ReposT (reason, abstracts), u) + + | AbstractsT (reason, abstracts), + AssertNonabstractT (use_op, reason_op, NonabstractMember (static, n)) -> + let abstracts = if static then fst abstracts else snd abstracts in + if SMap.mem n abstracts then + let error = FlowError.(EUnimplementedAbstract { + use_op; reason; reason_op; static; name = n + }) in + add_output cx ~trace error + + | AbstractsT (reason, (static_abstracts, abstracts)), + AssertNonabstractT (use_op, reason_op, NonabstractClass) -> + if not (SMap.is_empty static_abstracts && SMap.is_empty abstracts) then + let error = FlowError.(EUnimplementedAbstracts { + use_op; reason; reason_op; + static_abstracts = SMap.values static_abstracts; + abstracts = SMap.values abstracts; + }) in + add_output cx ~trace error + + | ObjProtoT _, AssertNonabstractT _ + | FunProtoT _, AssertNonabstractT _ + | DefT (_, NullT), AssertNonabstractT _ + | DefT (_, VoidT), AssertNonabstractT _ -> + () + + | AbstractsT (reason, abstracts_l), + UseT (use_op, AbstractsT (reason_op, abstracts_u)) -> + let diff = SMap.merge (fun _ l r -> + match l, r with + | Some _, None -> l + | _ -> None + ) in + let static_abstracts = diff (fst abstracts_l) (fst abstracts_u) in + let abstracts = diff (snd abstracts_l) (snd abstracts_u) in + if not (SMap.is_empty static_abstracts && SMap.is_empty abstracts) then + let error = FlowError.(EUnimplementedAbstracts { + use_op; reason; reason_op; + static_abstracts = SMap.values static_abstracts; + abstracts = SMap.values abstracts + }) in + add_output cx ~trace error + (*********************) (* type applications *) (*********************) @@ -3048,6 +3136,10 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = | DefT (_, IntersectionT rep), SuperT _ -> InterRep.members rep |> List.iter (fun t -> rec_flow cx trace (t, u)) + (** mixins cannot contain intersections **) + | DefT (reason, IntersectionT _), MixinT (_, reason_op, _) -> + add_output cx ~trace (FlowError.EIllegalMixin { reason; reason_op }) + (** structural subtype multiple inheritance **) | DefT (_, IntersectionT rep), ImplementsT _ -> InterRep.members rep |> List.iter (fun t -> rec_flow cx trace (t, u)) @@ -3609,25 +3701,28 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = (* A class can be viewed as a mixin by extracting its immediate properties, and "erasing" its static and super *) - | ThisClassT (_, DefT (_, InstanceT (_, _, _, instance))), MixinT (r, tvar) -> + | ThisClassT (_, DefT (_, InstanceT (_, _, _, instance)), abstracts), + MixinT (use_op, r, tvar) -> let static = ObjProtoT r in let super = ObjProtoT r in + let instance = DefT (r, InstanceT (static, super, [], instance)) in rec_flow cx trace ( - this_class_type (DefT (r, InstanceT (static, super, [], instance))), - UseT (unknown_use, tvar) + this_class_type instance abstracts, + UseT (use_op, tvar) ) - | DefT (_, PolyT (xs, ThisClassT (_, DefT (_, InstanceT (_, _, _, insttype))), _)), - MixinT (r, tvar) -> + | DefT (_, PolyT (xs, ThisClassT (_, DefT (_, InstanceT (_, _, _, insttype)), abstracts), _)), + MixinT (use_op, r, tvar) -> let static = ObjProtoT r in let super = ObjProtoT r in let instance = DefT (r, InstanceT (static, super, [], insttype)) in + let mixin = this_class_type instance abstracts in rec_flow cx trace ( - poly_type (Context.make_nominal cx) xs (this_class_type instance), - UseT (unknown_use, tvar) + poly_type (Context.make_nominal cx) xs mixin, + UseT (use_op, tvar) ) - | DefT (_, AnyT), MixinT (r, tvar) -> + | DefT (_, AnyT), MixinT (_, r, tvar) -> rec_flow_t cx trace (AnyT.why r, tvar) (* TODO: it is conceivable that other things (e.g. functions) could also be @@ -3698,21 +3793,21 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = ) (* empty targs specialization of non-polymorphic classes is a no-op *) - | (DefT (_, ClassT _) | ThisClassT _), SpecializeT(_,_,_,_,None,tvar) -> - rec_flow_t cx trace (l, tvar) + | (DefT (_, ClassT _) | ThisClassT _), SpecializeT(use_op,_,_,_,None,tvar) -> + rec_flow_t cx trace ~use_op (l, tvar) | DefT (_, AnyT), SpecializeT (_, _, _, _, _, tvar) -> rec_flow_t cx trace (l, tvar) (* this-specialize a this-abstracted class by substituting This *) - | ThisClassT (reason, i), ThisSpecializeT(_, this, tvar) -> + | ThisClassT (r, i, abstracts), ThisSpecializeT(_, this, tvar) -> let i = subst cx (SMap.singleton "this" this) i in - rec_flow_t cx trace (DefT (reason, ClassT i), tvar) + rec_flow_t cx trace (DefT (r, ClassT (i, abstracts)), tvar) (* this-specialization of non-this-abstracted classes is a no-op *) - | DefT (r, ClassT i), ThisSpecializeT(_, _this, tvar) -> + | DefT (r, ClassT (i, abstracts)), ThisSpecializeT(_, _this, tvar) -> (* TODO: check that this is a subtype of i? *) - rec_flow_t cx trace (DefT (r, ClassT i), tvar) + rec_flow_t cx trace (DefT (r, ClassT (i, abstracts)), tvar) | DefT (_, AnyT), ThisSpecializeT (_, _, tvar) -> rec_flow_t cx trace (l, tvar) @@ -3766,9 +3861,10 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = (* TODO: ideally we'd do the same when lower bounds flow to a this-abstracted class, but fixing the class is easier; might need to revisit *) - | (_, UseT (use_op, ThisClassT (r, i))) -> + | (_, UseT (use_op, ThisClassT (r, i, abstracts))) -> let reason = reason_of_t l in - rec_flow cx trace (l, UseT (use_op, fix_this_class cx trace reason (r, i))) + let cls = fix_this_class cx trace reason (r, i, abstracts) in + rec_flow cx trace (l, UseT (use_op, cls)) (** This rule is hit when a polymorphic type appears outside a type application expression - i.e. not followed by a type argument list @@ -3845,9 +3941,9 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = end (* when a this-abstracted class flows to upper bounds, fix the class *) - | (ThisClassT (r, i), _) -> + | (ThisClassT (r, i, abstracts), _) -> let reason = reason_of_use_t u in - rec_flow cx trace (fix_this_class cx trace reason (r, i), u) + rec_flow cx trace (fix_this_class cx trace reason (r, i, abstracts), u) (***********************************************) (* function types deconstruct into their parts *) @@ -4088,8 +4184,8 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = | CustomFunT (_, Mixin), CallT (_, reason_op, { call_args_tlist; call_tout; _ }) -> - let t = class_type (spread_objects cx reason_op call_args_tlist) in - rec_flow_t cx trace (t, call_tout) + let spread = spread_objects cx reason_op call_args_tlist in + rec_flow_t cx trace (nonabstract_class_type spread, call_tout) | CustomFunT (_, DebugPrint), CallT (_, reason_op, { call_args_tlist; call_tout; _ }) -> @@ -4169,10 +4265,10 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = rec_flow_p cx trace ~use_op lreason ureason propref (lp, up) | _ -> match up with - | Field (_, DefT (_, OptionalT ut), upolarity) -> + | Field ((kind, _, DefT (_, OptionalT ut)), upolarity) -> rec_flow cx trace (l, LookupT (ureason, NonstrictReturning None, [], propref, - LookupProp (use_op, Field (None, ut, upolarity)))) + LookupProp (use_op, Field ((kind, None, ut), upolarity)))) | _ -> let u = LookupT (ureason, Strict lreason, [], propref, @@ -4215,16 +4311,16 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = | _ -> Strict reason in let action = match u with - | UseT (use_op, (DefT (_, (FunT _ | AnyFunT)) as u_def)) -> + | UseT (use_op, (DefT (r, (FunT _ | AnyFunT)) as u_def)) -> let use_op = Frame (PropertyCompatibility { prop = Some "$call"; lower = reason; upper = reason_op; is_sentinel = false; }, use_op) in - LookupProp (use_op, Field (None, u_def, Positive)) - | _ -> - RWProp (use_op, l, tvar, Read) + let kind = Property.Explicit (loc_of_reason r) in + LookupProp (use_op, Field ((kind, None, u_def), Positive)) + | _ -> RWProp (use_op, l, tvar, Read) in lookup_prop cx trace l reason_op reason strict "$call" action; rec_flow cx trace (tvar, u) @@ -4403,7 +4499,7 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = (* runtime types derive static types through annotation *) (********************************************************) - | DefT (_, ClassT it), UseT (_, DefT (r, TypeT t)) -> + | DefT (_, ClassT (it, _)), UseT (_, DefT (r, TypeT t)) -> (* a class value annotation becomes the instance type *) rec_flow cx trace (it, BecomeT (r, t)) @@ -4423,25 +4519,27 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = let reasons = FlowError.ordered_reasons (reason_of_t l, ru) in add_output cx ~trace (FlowError.EValueUsedAsType reasons) - | DefT (rl, ClassT l), UseT (use_op, DefT (_, ClassT u)) -> - rec_flow cx trace ( - reposition cx ~trace (loc_of_reason rl) l, - UseT (use_op, u)) + | DefT (rl, ClassT (l, abstracts_l)), + UseT (use_op, DefT (ru, ClassT (u, abstracts_u))) -> + rec_flow_t cx trace (ReposT (rl, abstracts_l), ReposT (ru, abstracts_u)); + rec_flow cx trace (ReposT (rl, l), UseT (use_op, u)) | DefT (_, FunT (static1, prototype, _)), - UseT (use_op, DefT (_, ClassT (DefT (_, InstanceT (static2, _, _, _)) as u_))) -> + UseT (use_op, DefT (_, ClassT (DefT (_, InstanceT (static2, _, _, _)) as u_, _))) -> rec_unify cx trace ~use_op static1 static2; rec_unify cx trace ~use_op prototype u_ - | DefT (_, AnyT), UseT (use_op, DefT (_, ClassT u)) -> + | DefT (_, AnyT), UseT (use_op, DefT (_, ClassT (u, _))) -> rec_flow cx trace (l, UseT (use_op, u)) (*********************************************************) (* class types derive instance types (with constructors) *) (*********************************************************) - | DefT (reason, ClassT this), + | DefT (reason, ClassT (this, abstracts)), ConstructorT (use_op, reason_op, args, t) -> + let assertion = AssertNonabstractT (use_op, reason_op, NonabstractClass) in + rec_flow cx trace (ReposT (reason, abstracts), assertion); let reason_o = replace_reason_const RConstructorReturn reason in (* call this.constructor(args) *) let ret = Tvar.mk_where cx reason_op (fun t -> @@ -4644,7 +4742,7 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = (*****************************) | DefT (_, InstanceT _) as instance, GetPropT (_, _, Named (_, "constructor"), t) -> - rec_flow_t cx trace (class_type instance, t) + rec_flow_t cx trace (nonabstract_class_type instance, t) | DefT (reason_c, InstanceT (_, super, _, instance)), GetPropT (use_op, reason_op, Named (reason_prop, x), tout) -> @@ -4872,6 +4970,7 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = | DefT (reason, MixedT _), ObjAssignFromT _ -> let dict = { dict_name = None; + dict_kind = Property.Explicit (loc_of_reason reason); key = StrT.make reason; value = l; dict_polarity = Neutral; @@ -5005,7 +5104,8 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = * covariant props, which would always flow into `any`. *) () | _ -> - let p = Field (None, AnyT.why reason_op, Neutral) in + let kind = Property.Explicit (loc_of_reason reason_op) in + let p = Field ((kind, None, AnyT.why reason_op), Neutral) in perform_lookup_action cx trace propref p reason reason_op action) (*****************************************) @@ -5299,9 +5399,11 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = | DefT (_, FunT (_, t, _)), GetPropT (_, _, Named (_, "prototype"), tout) -> rec_flow_t cx trace (t, tout) - | DefT (reason, ClassT instance), GetPropT (_, _, Named (_, "prototype"), tout) -> - let instance = reposition cx ~trace (loc_of_reason reason) instance in - rec_flow_t cx trace (instance, tout) + | DefT (reason, ClassT (instance, abstracts)), + GetPropT(use_op, reason_op, Named (_, "prototype"), tout) -> + let assertion = AssertNonabstractT (use_op, reason_op, NonabstractClass) in + rec_flow cx trace (ReposT (reason, abstracts), assertion); + rec_flow_t cx trace (ReposT (reason, instance), tout) (**************************************) (* ... and their fields/elements read *) @@ -5314,7 +5416,8 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = rec_flow_t cx trace (AnyT.why reason_op, tout) | DefT (reason_fun, AnyFunT), LookupT (reason_op, _, _, x, action) -> - let p = Field (None, AnyT.why reason_op, Neutral) in + let kind = Property.Explicit (loc_of_reason reason_op) in + let p = Field ((kind, None, AnyT.why reason_op), Neutral) in perform_lookup_action cx trace x p reason_fun reason_op action (*****************************************) @@ -5762,15 +5865,36 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = * Instead, we just flip the boolean flag to true, indicating that when the * InstanceT ~> Set/GetPrivatePropT constraint is processed that we should look at the * private static fields instead of the private instance fields. *) - | DefT (reason, ClassT instance), GetPrivatePropT (use_op, reason_op, x, scopes, _, tout) -> + | DefT (reason, ClassT (instance, _)), GetPrivatePropT (use_op, reason_op, x, scopes, _, tout) -> let u = GetPrivatePropT (use_op, reason_op, x, scopes, true, tout) in rec_flow cx trace (instance, ReposLowerT (reason, false, u)) - | DefT (reason, ClassT instance), SetPrivatePropT (use_op, reason_op, x, scopes, _, tout, tp) -> + | DefT (reason, ClassT (instance, _)), SetPrivatePropT (use_op, reason_op, x, scopes, _, tout, tp) -> let u = SetPrivatePropT (use_op, reason_op, x, scopes, true, tout, tp) in rec_flow cx trace (instance, ReposLowerT (reason, false, u)) - | DefT (reason, ClassT instance), _ when object_use u || object_like_op u -> + | DefT (reason, ClassT (instance, abstracts)), _ + when object_use u || object_like_op u -> + begin match u with + | SetPropT _ -> () + | UseT (use_op, _) + | GetPropT (use_op, _, _, _) + | MethodT (use_op, _, _, _, _, _) + | SuperT (use_op, _, _) + | SetElemT (use_op, _, _, _, _) + | GetElemT (use_op, _, _, _) -> + let assertion = + let kind = NonabstractClass in + AssertNonabstractT (use_op, reason_of_use_t u, kind) + in + rec_flow cx trace (ReposT (reason, abstracts), assertion) + | _ -> + let assertion = + let kind = NonabstractClass in + AssertNonabstractT (unknown_use, reason_of_use_t u, kind) + in + rec_flow cx trace (ReposT (reason, abstracts), assertion) + end; let desc = RStatics (desc_of_reason (reason_of_t instance)) in let loc = loc_of_reason reason in let reason = mk_reason desc loc in @@ -5873,7 +5997,8 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = let use_op = use_op_of_lookup_action action in add_output cx ~trace (FlowError.EStrictLookupFailed ((reason_prop, strict_reason), reason, Some x, use_op)); - let p = Field (None, AnyT.why reason_op, Neutral) in + let kind = Property.Explicit (loc_of_reason reason_op) in + let p = Field ((kind, None, AnyT.why reason_op), Neutral) in perform_lookup_action cx trace propref p reason reason_op action | (DefT (reason, NullT) | ObjProtoT reason | FunProtoT reason), @@ -5889,7 +6014,8 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = | DefT (_, AnyT) | DefT (_, StrT _) | DefT (_, NumT _) -> (* any, string, and number keys are allowed, but there's nothing else to flow without knowing their literal values. *) - let p = Field (None, AnyT.why reason_op, Neutral) in + let kind = Property.Explicit (loc_of_reason reason_op) in + let p = Field ((kind, None, AnyT.why reason_op), Neutral) in perform_lookup_action cx trace propref p reason reason_op action | _ -> let reason_prop = reason_of_t elem_t in @@ -5934,6 +6060,7 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = | None -> (* Create prop and link shadow props along the proto chain. *) let reason_prop = replace_reason_const (RShadowProperty x) reason_op in + let kind = Property.Explicit (loc_of_reason reason_prop) in let t = Tvar.mk cx reason_prop in let prop_loc = def_loc_of_reason lookup_reason in (match proto_ids with @@ -5943,7 +6070,7 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = let t_proto = Property.assert_field p_proto in rec_flow cx trace (t_proto, UnifyT (t_proto, t))); (* Add prop *) - let p = Field (Some prop_loc, t, Neutral) in + let p = Field ((kind, Some prop_loc, t), Neutral) in pmap |> SMap.add x p |> Context.add_property_map cx id; @@ -6000,7 +6127,7 @@ let rec __flow cx ((l: Type.t), (u: Type.use_t)) trace = let l = reposition cx ~trace (loc_of_reason lreason) proto_t in rec_flow cx trace (l, u) - | DefT (reason, ClassT instance), ExtendsUseT _ -> + | DefT (reason, ClassT (instance, _)), ExtendsUseT _ -> let desc = RStatics (desc_of_reason (reason_of_t instance)) in let loc = loc_of_reason reason in let reason = mk_reason desc loc in @@ -6385,22 +6512,22 @@ and flow_obj_to_obj cx trace ~use_op (lreason, l_obj) (ureason, u_obj) = (* If both are dictionaries, ensure the keys and values are compatible with each other. *) (match ldict, udict with - | Some {key = lk; value = lv; dict_polarity = lpolarity; _}, - Some {key = uk; value = uv; dict_polarity = upolarity; _} -> + | Some {dict_kind = lkind; key = lk; value = lv; dict_polarity = lpolarity; _}, + Some {dict_kind = ukind; key = uk; value = uv; dict_polarity = upolarity; _} -> (* Don't report polarity errors when checking the indexer key. We would * report these errors again a second time when checking values. *) rec_flow_p cx trace ~report_polarity:false ~use_op:(Frame (IndexerKeyCompatibility { lower = lreason; upper = ureason; }, use_op)) lreason ureason (Computed uk) - (Field (None, lk, lpolarity), Field (None, uk, upolarity)); + (Field ((lkind, None, lk), lpolarity), Field ((ukind, None, uk), upolarity)); rec_flow_p cx trace ~use_op:(Frame (PropertyCompatibility { prop = None; lower = lreason; upper = ureason; is_sentinel = false; }, use_op)) lreason ureason (Computed uv) - (Field (None, lv, lpolarity), Field (None, uv, upolarity)) + (Field ((lkind, None, lv), lpolarity), Field ((ukind, None, uv), upolarity)) | _ -> ()); (* Properties in u must either exist in l, or match l's indexer. *) @@ -6431,16 +6558,16 @@ and flow_obj_to_obj cx trace ~use_op (lreason, l_obj) (ureason, u_obj) = (* prop from aliased LB *) rec_flow_p cx trace ~use_op lreason ureason propref (lp, up) ) - | None, Some { key; value; dict_polarity; _ } + | None, Some { dict_kind; key; value; dict_polarity; _ } when not (is_dictionary_exempt s) -> rec_flow cx trace (string_key s reason_prop, UseT ( Frame (IndexerKeyCompatibility {lower = lreason; upper = ureason}, use_op'), key )); - let lp = Field (None, value, dict_polarity) in + let lp = Field ((dict_kind, None, value), dict_polarity) in let up = match up with - | Field (loc, DefT (_, OptionalT ut), upolarity) -> - Field (loc, ut, upolarity) + | Field ((kind, key_loc, DefT (_, OptionalT ut)), upolarity) -> + Field ((kind, key_loc, ut), upolarity) | _ -> up in if lit @@ -6453,7 +6580,7 @@ and flow_obj_to_obj cx trace ~use_op (lreason, l_obj) (ureason, u_obj) = | _ -> (* property doesn't exist in inflowing type *) match up with - | Field (_, DefT (_, OptionalT _), _) when lit -> + | Field ((_, _, DefT (_, OptionalT _)), _) when lit -> (* if property is marked optional or otherwise has a maybe type, and if inflowing type is a literal (i.e., it is not an annotation), then we add it to the inflowing type as @@ -6486,7 +6613,7 @@ and flow_obj_to_obj cx trace ~use_op (lreason, l_obj) (ureason, u_obj) = (* Any properties in l but not u must match indexer *) (match udict with | None -> () - | Some { key; value; dict_polarity; _ } -> + | Some { dict_kind; key; value; dict_polarity; _ } -> iter_real_props cx lflds (fun ~is_sentinel s lp -> if not (Context.has_prop cx uflds s) then ( @@ -6501,11 +6628,11 @@ and flow_obj_to_obj cx trace ~use_op (lreason, l_obj) (ureason, u_obj) = is_sentinel; }, use_op) in let lp = match lp with - | Field (loc, DefT (_, OptionalT lt), lpolarity) -> - Field (loc, lt, lpolarity) + | Field ((kind, key_loc, DefT (_, OptionalT lt)), lpolarity) -> + Field ((kind, key_loc, lt), lpolarity) | _ -> lp in - let up = Field (None, value, dict_polarity) in + let up = Field ((dict_kind, None, value), dict_polarity) in if lit then match Property.read_t lp, Property.read_t up with @@ -6565,7 +6692,7 @@ and quick_error_fun_as_obj cx trace ~use_op reason statics reason_o props = | Some statics_own_props -> let props_not_found = SMap.filter (fun x p -> let optional = match p with - | Field (_, DefT (_, OptionalT _), _) -> true + | Field ((_, _, DefT (_, OptionalT _)), _) -> true |_ -> false in not ( @@ -6829,7 +6956,7 @@ and structural_subtype cx trace ?(use_op=unknown_use) lower reason_struct is_sentinel = false; }, use_op) in match p with - | Field (_, DefT (_, OptionalT t), polarity) -> + | Field ((kind, _, DefT (_, OptionalT t)), polarity) -> let propref = let reason_prop = replace_reason (fun desc -> ROptional (RPropertyOf (s, desc)) @@ -6838,7 +6965,7 @@ and structural_subtype cx trace ?(use_op=unknown_use) lower reason_struct in rec_flow cx trace (lower, LookupT (reason_struct, NonstrictReturning None, [], propref, - LookupProp (use_op, Field (None, t, polarity)))) + LookupProp (use_op, Field ((kind, None, t), polarity)))) | _ -> let propref = let reason_prop = replace_reason (fun desc -> @@ -6932,10 +7059,10 @@ and subst = let changed = changed || inner_ != inner in if changed then DefT (reason, PolyT (List.rev xs, inner_, mk_id ())) else t - | ThisClassT (reason, this) -> + | ThisClassT (reason, this, abstracts) -> let map = SMap.remove "this" map in let this_ = self#type_ cx (map, force, use_op) this in - if this_ == this then t else ThisClassT (reason, this_) + if this_ == this then t else ThisClassT (reason, this_, abstracts) | EvalT (x, TypeDestructorT (op, r, d), _) -> let x' = self#type_ cx map_cx x in @@ -7144,7 +7271,7 @@ and check_polarity cx ?trace polarity = function | InternalT (ReposUpperT (_, t)) -> check_polarity cx ?trace polarity t - | DefT (_, ClassT t) + | DefT (_, ClassT (t, _)) -> check_polarity cx ?trace polarity t | DefT (_, TypeT t) @@ -7213,6 +7340,7 @@ and check_polarity cx ?trace polarity = function check_polarity cx ?trace Positive t | ThisClassT _ + | AbstractsT _ | ModuleT _ | AnnotT _ | MatchingPropT _ @@ -7240,13 +7368,15 @@ and check_polarity_propmap cx ?trace ?(skip_ctor=false) polarity id = ) pmap and check_polarity_prop cx ?trace polarity = function - | Field (_, t, p) -> check_polarity cx ?trace (Polarity.mult (polarity, p)) t - | Get (_, t) -> check_polarity cx ?trace polarity t - | Set (_, t) -> check_polarity cx ?trace (Polarity.inv polarity) t - | GetSet (_, t1, _, t2) -> + | Field ((_, _, t), p) -> + check_polarity cx ?trace (Polarity.mult (polarity, p)) t + | Get (_, _, t) -> check_polarity cx ?trace polarity t + | Set (_, _, t) -> check_polarity cx ?trace (Polarity.inv polarity) t + | GetSet ((_, _, t1), (_, _, t2)) -> check_polarity cx ?trace polarity t1; check_polarity cx ?trace (Polarity.inv polarity) t2 - | Method (_, t) -> check_polarity cx ?trace polarity t + | Method (_, _, t) + | Abstract (_, _, t) -> check_polarity cx ?trace polarity t and check_polarity_typeparam cx ?trace polarity tp = let polarity = Polarity.mult (polarity, tp.polarity) in @@ -7362,7 +7492,7 @@ and instantiate_poly_param_upper_bounds cx typeparams = fixpoint is some `this`, substitute it as This in the instance type, and finally unify it with the instance type. Return the class type wrapping the instance type. *) -and fix_this_class cx trace reason (r, i) = +and fix_this_class cx trace reason (r, i, abstracts) = let i' = match Cache.Fix.find reason i with | Some i' -> i' | None -> @@ -7372,17 +7502,17 @@ and fix_this_class cx trace reason (r, i) = rec_unify cx trace ~use_op:unknown_use this i'; i' in - DefT (r, ClassT i') + DefT (r, ClassT (i', abstracts)) and canonicalize_imported_type cx trace reason t = match t with - | DefT (_, ClassT inst) -> + | DefT (_, ClassT (inst, _)) -> Some (DefT (reason, TypeT inst)) | DefT (_, FunT (_, prototype, _)) -> Some (DefT (reason, TypeT prototype)) - | DefT (_, PolyT (typeparams, DefT (_, ClassT inst), id)) -> + | DefT (_, PolyT (typeparams, DefT (_, ClassT (inst, _)), id)) -> Some (poly_type id typeparams (DefT (reason, TypeT inst))) | DefT (_, PolyT (typeparams, DefT (_, FunT (_, prototype, _)), id)) -> @@ -7392,14 +7522,14 @@ and canonicalize_imported_type cx trace reason t = by transforming the instance type to a type application *) | DefT (_, PolyT (typeparams, ThisClassT _, id)) -> let targs = List.map (fun tp -> BoundT tp) typeparams in - Some (poly_type id typeparams (class_type (typeapp t targs))) + Some (poly_type id typeparams (nonabstract_class_type (typeapp t targs))) | DefT (_, PolyT (_, DefT (_, TypeT _), _)) -> Some t (* fix this-abstracted class when used as a type *) - | ThisClassT(r, i) -> - Some (fix_this_class cx trace reason (r, i)) + | ThisClassT(r, i, abstracts) -> + Some (fix_this_class cx trace reason (r, i, abstracts)) | DefT (_, TypeT _) -> Some t @@ -8136,7 +8266,7 @@ and guess_and_record_sentinel_prop cx ts = (* Keep only fields that have singleton types *) let acc = SMap.filter (fun _ p -> match p with - | Field (_, t, _) -> is_singleton_type t + | Field ((_, _, t), _) -> is_singleton_type t | _ -> false ) acc in @@ -8252,14 +8382,14 @@ and get_obj_prop cx trace o propref reason_op = | _, Some _, _ -> (* Property exists on this property map *) named_prop - | Named (_, x), None, Some { key; value; dict_polarity; _ } + | Named (_, x), None, Some { dict_kind; key; value; dict_polarity; _ } when not (is_dictionary_exempt x) -> (* Dictionaries match all property reads *) rec_flow_t cx trace (string_key x reason_op, key); - Some (Field (None, value, dict_polarity)) - | Computed k, None, Some { key; value; dict_polarity; _ } -> + Some (Field ((dict_kind, None, value), dict_polarity)) + | Computed k, None, Some { dict_kind; key; value; dict_polarity; _ } -> rec_flow_t cx trace (k, key); - Some (Field (None, value, dict_polarity)) + Some (Field ((dict_kind, None, value), dict_polarity)) | _ -> None and read_obj_prop cx trace ~use_op o propref reason_obj reason_op tout = @@ -8337,8 +8467,9 @@ and write_obj_prop cx trace ~use_op o propref reason_obj reason_op tin prop_t = and find_or_intro_shadow_prop cx trace reason_op x prop_loc = let intro_shadow_prop id = let reason_prop = replace_reason_const (RShadowProperty x) reason_op in + let kind = Property.Explicit (loc_of_reason reason_prop) in let t = Tvar.mk cx reason_prop in - let p = Field (Some prop_loc, t, Neutral) in + let p = Field ((kind, Some prop_loc, t), Neutral) in Context.set_prop cx id (internal_name x) p; t, p in @@ -8747,7 +8878,7 @@ and instanceof_test cx trace result = function first. *) | true, (DefT (reason, ArrT arrtype) as arr), - DefT (r, ClassT (DefT (_, (InstanceT _)) as a)) -> + DefT (r, ClassT (DefT (_, (InstanceT _)) as a, _)) -> let elemt = elemt_of_arrtype reason arrtype in @@ -8757,7 +8888,7 @@ and instanceof_test cx trace result = function | false, (DefT (reason, ArrT arrtype) as arr), - DefT (r, ClassT (DefT (_, (InstanceT _)) as a)) -> + DefT (r, ClassT (DefT (_, (InstanceT _)) as a, _)) -> let elemt = elemt_of_arrtype reason arrtype in @@ -8789,7 +8920,7 @@ and instanceof_test cx trace result = function subclass decisions.) **) | true, (DefT (_, InstanceT _) as c), - DefT (r, ClassT (DefT (_, (InstanceT _)) as a)) -> + DefT (r, ClassT (DefT (_, (InstanceT _)) as a, _)) -> predicate cx trace result (extends_type r c a) (RightP (InstanceofTest, c)) @@ -8834,7 +8965,7 @@ and instanceof_test cx trace result = function extends A, choosing either nothing or C based on the result. **) | false, (DefT (_, InstanceT _) as c), - DefT (r, ClassT (DefT (_, (InstanceT _)) as a)) -> + DefT (r, ClassT (DefT (_, (InstanceT _)) as a, _)) -> predicate cx trace result (extends_type r c a) (NotP(RightP(InstanceofTest, c))) @@ -9458,8 +9589,8 @@ and unify_props cx trace ~use_op x r1 r2 p1 p2 = (* If both sides are neutral fields, we can just unify once *) match p1, p2 with - | Field (_, t1, Neutral), - Field (_, t2, Neutral) -> + | Field ((_, _, t1), Neutral), + Field ((_, _, t2), Neutral) -> rec_unify cx trace ~use_op t1 t2; | _ -> (* Otherwise, unify read/write sides separately. *) @@ -9489,12 +9620,12 @@ and unify_prop_with_dict cx trace ~use_op x p prop_obj_reason dict_reason dict = prop_reason: reason of the prop itself *) let prop_reason = replace_reason_const (RProperty (Some x)) prop_obj_reason in match dict with - | Some { key; value; dict_polarity; _ } -> + | Some { dict_kind; key; value; dict_polarity; _ } -> rec_flow cx trace (string_key x prop_reason, UseT ( Frame (IndexerKeyCompatibility {lower = prop_obj_reason; upper = dict_reason}, use_op), key )); - let p2 = Field (None, value, dict_polarity) in + let p2 = Field ((dict_kind, None, value), dict_polarity) in unify_props cx trace ~use_op x prop_obj_reason dict_reason p p2 | None -> let use_op = Frame (PropertyCompatibility { @@ -10106,7 +10237,17 @@ and perform_lookup_action cx trace propref p lreason ureason = function | LookupProp (use_op, up) -> rec_flow_p cx trace ~use_op lreason ureason propref (p, up) | SuperProp (use_op, lp) -> - rec_flow_p cx trace ~use_op ureason lreason propref (lp, p) + begin match lp, p with + | Abstract _, (Field _ | Get _ | Set _ | GetSet _ | Method _) -> + lp |> Property.iter_reason (fun abstract -> + p |> Property.iter_reason FlowError.(fun nonabstract -> + add_output cx ~trace (EAbstractMask { nonabstract; abstract }))) + | Set _, Abstract _ -> + lp |> Property.iter_reason (fun setter -> + p |> Property.iter_reason (fun abstract -> + add_output cx ~trace (FlowError.EAbstractSet { abstract; setter }))) + | _ -> rec_flow_p cx trace ~use_op ureason lreason propref (lp, p) + end | RWProp (use_op, _, tout, rw) -> begin match rw, Property.access rw p with (* TODO: Sam, comment repositioning logic here *) @@ -10183,7 +10324,13 @@ and mk_instance cx ?trace instance_reason ?(for_type=true) ?(use_desc=false) c = AnnotT (open_tvar source, use_desc) else Tvar.mk_derivable_where cx instance_reason (fun t -> - flow_opt_t cx ?trace (c, class_type t) + let abstracts = + let reason = replace_reason (fun desc -> + RAbstractsOf desc + ) instance_reason in + AnyT.why reason + in + flow_opt_t cx ?trace (c, class_type t abstracts) ) (* set the position of the given def type from a reason *) @@ -10332,7 +10479,7 @@ and instantiate_poly_t cx t = function and instantiate_type t = match t with - | ThisClassT (_, t) | DefT (_, ClassT t) -> t + | ThisClassT (_, t, _) | DefT (_, ClassT (t, _)) -> t | _ -> AnyT.why (reason_of_t t) (* ideally, assert false *) and call_args_iter f = List.iter (function Arg t | SpreadArg t -> f t) @@ -10404,8 +10551,8 @@ and rec_flow_t cx trace ?(use_op=unknown_use) (t1, t2) = and rec_flow_p cx trace ?(use_op=unknown_use) ?(report_polarity=true) lreason ureason propref = function (* unification cases *) - | Field (_, lt, Neutral), - Field (_, ut, Neutral) -> + | Field ((_, _, lt), Neutral), + Field ((_, _, ut), Neutral) -> rec_unify cx trace ~use_op lt ut (* directional cases *) | lp, up -> @@ -10716,14 +10863,12 @@ and object_kit = (*******************************) let read_prop r flags x p = - let t = match Property.read_t p with - | Some t -> t + match Property.read p with + | Some (kind, _, t) -> kind, t, flags.exact | None -> + let kind = Property.Member (x, loc_of_reason r) in let reason = replace_reason_const (RUnknownProperty (Some x)) r in - let t = DefT (reason, MixedT Mixed_everything) in - t - in - t, flags.exact + kind, DefT (reason, MixedT Mixed_everything), flags.exact in let read_dict r {value; dict_polarity; _} = @@ -10742,7 +10887,8 @@ and object_kit = let get_prop r p dict = match p, dict with | Some _, _ -> p - | None, Some d -> Some (optional (read_dict r d), true) + | None, Some ({ dict_kind; _ } as d) -> + Some (dict_kind, optional (read_dict r d), true) | None, None -> None in @@ -10770,14 +10916,14 @@ and object_kit = (* Compute spread result: slice * slice -> slice *) let spread2 reason (r1, props1, dict1, flags1) (r2, props2, dict2, flags2) = let union t1 t2 = DefT (reason, UnionT (UnionRep.make t1 t2 [])) in - let merge_props (t1, own1) (t2, own2) = + let merge_props x (_, t1, own1) (kind2, t2, own2) = let t1, opt1 = match t1 with DefT (_, OptionalT t) -> t, true | _ -> t1, false in let t2, opt2 = match t2 with DefT (_, OptionalT t) -> t, true | _ -> t2, false in (* An own, non-optional property definitely overwrites earlier properties. Otherwise, the type might come from either side. *) - let t, own = - if own2 && not opt2 then t2, own2 - else union t1 t2, own1 || own2 + let kind, t, own = + if own2 && not opt2 then kind2, t2, own2 + else Property.Member (x, loc_of_reason reason), union t1 t2, own1 || own2 in (* If either property is own, the result is non-optional unless the own property is itself optional. Non-own implies optional (see mk_object), @@ -10787,29 +10933,31 @@ and object_kit = else own1 && opt1 || own2 && opt2 in let t = if opt then optional t else t in - t, own + kind, t, own in let props = SMap.merge (fun x p1 p2 -> (* Due to width subtyping, failing to read from an inexact object does not imply non-existence, but rather an unknown result. *) let unknown r = let r = replace_reason_const (RUnknownProperty (Some x)) r in - DefT (r, MixedT Mixed_everything), false + let kind = Property.Member (x, loc_of_reason r) in + kind, DefT (r, MixedT Mixed_everything), false in match get_prop r1 p1 dict1, get_prop r2 p2 dict2 with | None, None -> None - | Some p1, Some p2 -> Some (merge_props p1 p2) + | Some p1, Some p2 -> Some (merge_props x p1 p2) | Some p1, None -> if flags2.exact then Some p1 - else Some (merge_props p1 (unknown r2)) + else Some (merge_props x p1 (unknown r2)) | None, Some p2 -> if flags1.exact then Some p2 - else Some (merge_props (unknown r1) p2) + else Some (merge_props x (unknown r1) p2) ) props1 props2 in let dict = Option.merge dict1 dict2 (fun d1 d2 -> { dict_name = None; + dict_kind = Property.Custom ("member indexer", loc_of_reason reason); key = union d1.key d2.key; value = union (read_dict r1 d1) (read_dict r2 d2); dict_polarity = Neutral @@ -10831,14 +10979,14 @@ and object_kit = in let mk_object cx reason target (r, props, dict, flags) = - let props = SMap.map (fun (t, own) -> + let props = SMap.map (fun (kind, t, own) -> (* Spread only copies over own properties. If `not own`, then the property might be on a proto object instead, so make the result optional. *) let t = match t with | DefT (_, OptionalT _) -> t | _ -> if own then t else optional t in - Field (None, t, Neutral) + Field ((kind, None, t), Neutral) ) props in let id = Context.make_property_map cx props in let proto = ObjProtoT reason in @@ -10926,13 +11074,13 @@ and object_kit = * subtracted and so is optional. If props2 is not exact then we may * optionally have some undocumented prop. *) | (Sound | IgnoreExactAndOwn), - Some (t1, _), Some ((DefT (_, OptionalT _) as t2), _), _ + Some (kind1, t1, _), Some (_, (DefT (_, OptionalT _) as t2), _), _ | Sound, - Some (t1, _), Some (t2, false), _ + Some (kind1, t1, _), Some (_, t2, false), _ | Sound, - Some (t1, _), Some (t2, _), false -> + Some (kind1, t1, _), Some (_, t2, _), false -> rec_flow cx trace (t1, UseT (use_op, optional t2)); - Some (Field (None, optional t1, Neutral)) + Some (Field ((kind1, None, optional t1), Neutral)) (* Otherwise if the object we are using to subtract has a non-optional own * property and the object is exact then we never add that property to our @@ -10941,23 +11089,21 @@ and object_kit = * If we are using ReactConfigMerge then make the property optional * instead of removing it entirely. *) | (Sound | IgnoreExactAndOwn | ReactConfigMerge), - None, Some (t2, _), _ -> + None, Some (_, t2, _), _ -> let reason = replace_reason_const (RUndefinedProperty k) r1 in rec_flow cx trace (VoidT.make reason, UseT (use_op, t2)); None | (Sound | IgnoreExactAndOwn), - Some (t1, _), Some (t2, _), _ -> + Some (_, t1, _), Some (_, t2, _), _ -> rec_flow cx trace (t1, UseT (use_op, t2)); None (* If we have some property in our first object and none in our second * object, but our second object is inexact then we want to make our * property optional and flow that type to mixed. *) - | Sound, - Some (t1, _), None, false -> + | Sound, Some (kind1, t1, _), None, false -> rec_flow cx trace (t1, UseT (use_op, MixedT.make r2)); - Some (Field (None, optional t1, Neutral)) - + Some (Field ((kind1, None, optional t1), Neutral)) (* If neither object has the prop then we don't add a prop to our * result here. *) | (Sound | IgnoreExactAndOwn | ReactConfigMerge), @@ -10968,10 +11114,14 @@ and object_kit = * prop then we will copy over that prop. If the first object's prop is * non-own then sometimes we may not copy it over so we mark it * as optional. *) - | IgnoreExactAndOwn, Some (t, _), None, _ -> Some (Field (None, t, Neutral)) - | ReactConfigMerge, Some (t, _), None, _ -> Some (Field (None, t, Positive)) - | Sound, Some (t, true), None, _ -> Some (Field (None, t, Neutral)) - | Sound, Some (t, false), None, _ -> Some (Field (None, optional t, Neutral)) + | IgnoreExactAndOwn, Some (kind, t, _), None, _ -> + Some (Field ((kind, None, t), Neutral)) + | ReactConfigMerge, Some (kind, t, _), None, _ -> + Some (Field ((kind, None, t), Positive)) + | Sound, Some (kind, t, true), None, _ -> + Some (Field ((kind, None, t), Neutral)) + | Sound, Some (kind, t, false), None, _ -> + Some (Field ((kind, None, optional t), Neutral)) (* React config merging is special. We are trying to solve for C * in the equation (where ... represents spread instead of rest): @@ -10987,9 +11137,9 @@ and object_kit = * the behavior of other object rest merge modes implemented in this * pattern match. *) | ReactConfigMerge, - Some (t1, _), Some ((DefT (_, OptionalT _) as t2), _), _ -> + Some (kind1, t1, _), Some (_, (DefT (_, OptionalT _) as t2), _), _ -> rec_flow_t cx trace (t1, optional t2); - Some (Field (None, t1, Positive)) + Some (Field ((kind1, None, t1), Positive)) (* Using our same equation. Consider this case: * * {...{p}, ...C} = {p} @@ -10999,10 +11149,9 @@ and object_kit = * {|p?|} is the best solution since it accepts more valid * programs then {||}. *) | ReactConfigMerge, - Some (t1, _), Some (t2, _), _ -> + Some (kind1, t1, _), Some (_, t2, _), _ -> rec_flow_t cx trace (t1, t2); - Some (Field (None, optional t1, Positive)) - + Some (Field ((kind1, None, optional t1), Positive)) ) props1 props2 in let dict = match dict1, dict2 with | None, None -> None @@ -11015,6 +11164,7 @@ and object_kit = rec_flow cx trace (dict1.value, UseT (use_op, dict2.value)); Some ({ dict_name = None; + dict_kind = dict1.dict_kind; key = dict1.key; value = optional dict1.value; dict_polarity = Neutral; @@ -11060,7 +11210,9 @@ and object_kit = let mk_read_only_object cx reason slice = let (r, props, dict, flags) = slice in - let props = SMap.map (fun (t, _) -> Field (None, t, polarity)) props in + let props = SMap.map (fun (kind, t, _) -> + Field ((kind, None, t), polarity) + ) props in let dict = Option.map dict (fun dict -> { dict with dict_polarity = polarity }) in let id = Context.make_property_map cx props in let proto = ObjProtoT reason in @@ -11098,7 +11250,8 @@ and object_kit = * to our config props. *) let config_props = Option.value_map children ~default:config_props ~f:(fun children -> - SMap.add "children" (children, true) config_props + let kind = Property.Explicit (loc_of_t children) in + SMap.add "children" (kind, children, true) config_props ) in (* Remove the key and ref props from our config. We check key and ref @@ -11115,13 +11268,14 @@ and object_kit = * default props to our final props object. *) | Some (defaults_reason, defaults_props, defaults_dict, defaults_flags) -> (* Merge our props and default props. *) - let props = SMap.merge (fun _ p1 p2 -> + let props = SMap.merge (fun x p1 p2 -> let p1 = get_prop config_reason p1 config_dict in let p2 = get_prop defaults_reason p2 defaults_dict in match p1, p2 with | None, None -> None - | Some (t, _), None -> Some (Field (None, t, prop_polarity)) - | None, Some (t, _) -> Some (Field (None, t, prop_polarity)) + | Some (kind, t, _), None + | None, Some (kind, t, _) -> + Some (Field ((kind, None, t), prop_polarity)) (* If a property is defined in both objects, and the first property's * type includes void then we want to replace every occurrence of void * with the second property's type. This is consistent with the behavior @@ -11129,17 +11283,19 @@ and object_kit = * `f(undefined)` and there is a default value for the first argument, * then we will ignore the void type and use the type for the default * parameter instead. *) - | Some (t1, _), Some (t2, _) -> + | Some (_, t1, _), Some (_, t2, _) -> (* Use CondT to replace void with t1. *) let t = Tvar.mk_where cx reason (fun tvar -> rec_flow cx trace (filter_optional cx ~trace reason t1, CondT (reason, t2, tvar)) ) in - Some (Field (None, t, prop_polarity)) + let kind = Property.Member (x, loc_of_t t) in + Some (Field ((kind, None, t), prop_polarity)) ) config_props defaults_props in (* Merge the dictionary from our config with the defaults dictionary. *) let dict = Option.merge config_dict defaults_dict (fun d1 d2 -> { dict_name = None; + dict_kind = Property.Custom ("member indexer", loc_of_reason reason); key = DefT (reason, UnionT (UnionRep.make d1.key d2.key [])); value = DefT (reason, UnionT (UnionRep.make (read_dict config_reason d1) @@ -11161,11 +11317,14 @@ and object_kit = (* Otherwise turn our slice props map into an object props. *) | None -> (* All of the fields are read-only so we create positive fields. *) - let props = SMap.map (fun (t, _) -> Field (None, t, prop_polarity)) config_props in + let props = SMap.map (fun (kind, t, _) -> + Field ((kind, None, t), prop_polarity) + ) config_props in (* Create a new dictionary from our config's dictionary with a * positive polarity. *) let dict = Option.map config_dict (fun d -> { dict_name = None; + dict_kind = d.dict_kind; key = d.key; value = d.value; dict_polarity = prop_polarity; @@ -11240,35 +11399,39 @@ and object_kit = *) let intersect2 reason (r1, props1, dict1, flags1) (r2, props2, dict2, flags2) = let intersection t1 t2 = DefT (reason, IntersectionT (InterRep.make t1 t2 [])) in - let merge_props (t1, own1) (t2, own2) = + let merge_props x (_, t1, own1) (_, t2, own2) = let t1, t2, opt = match t1, t2 with | DefT (_, OptionalT t1), DefT (_, OptionalT t2) -> t1, t2, true | DefT (_, OptionalT t1), t2 | t1, DefT (_, OptionalT t2) | t1, t2 -> t1, t2, false in let t = intersection t1 t2 in let t = if opt then optional t else t in - t, own1 || own2 + Property.Member (x, loc_of_reason reason), t, own1 || own2 in let r = let loc = Loc.btwn (loc_of_reason r1) (loc_of_reason r2) in mk_reason RObjectType loc in - let props = SMap.merge (fun _ p1 p2 -> - let read_dict r d = optional (read_dict r d), true in + let props = SMap.merge (fun x p1 p2 -> + let read_dict r d = + let { dict_kind; _ } = d in + dict_kind, optional (read_dict r d), true + in match p1, p2 with | None, None -> None - | Some p1, Some p2 -> Some (merge_props p1 p2) + | Some p1, Some p2 -> Some (merge_props x p1 p2) | Some p1, None -> (match dict2 with - | Some d2 -> Some (merge_props p1 (read_dict r2 d2)) + | Some d2 -> Some (merge_props x p1 (read_dict r2 d2)) | None -> Some p1) | None, Some p2 -> (match dict1 with - | Some d1 -> Some (merge_props (read_dict r1 d1) p2) + | Some d1 -> Some (merge_props x (read_dict r1 d1) p2) | None -> Some p2) ) props1 props2 in let dict = Option.merge dict1 dict2 (fun d1 d2 -> { dict_name = None; + dict_kind = Property.Custom ("member indexer", loc_of_reason reason); key = intersection d1.key d2.key; value = intersection (read_dict r1 d1) (read_dict r2 d2); dict_polarity = Neutral; @@ -11306,6 +11469,7 @@ and object_kit = let props = SMap.mapi (read_prop r flags) props in let dict = Option.map dict (fun d -> { dict_name = None; + dict_kind = d.dict_kind; key = d.key; value = read_dict r d; dict_polarity = Neutral; @@ -11318,12 +11482,12 @@ and object_kit = let id, dict = let props = Context.find_props cx id in match SMap.get "$key" props, SMap.get "$value" props with - | Some (Field (_, key, polarity)), Some (Field (_, value, polarity')) - when polarity = polarity' -> + | Some (Field ((_, _, key), pol)), Some (Field ((_, _, value), pol')) + when pol = pol' -> let props = props |> SMap.remove "$key" |> SMap.remove "$value" in let id = Context.make_property_map cx props in - let dict = {dict_name = None; key; value; dict_polarity = polarity} in - id, Some dict + let dict_kind = Property.Custom ("member indexer", loc_of_reason r) in + id, Some {dict_name = None; dict_kind; key; value; dict_polarity = pol} | _ -> id, None in object_slice cx r id dict flags @@ -11362,6 +11526,7 @@ and object_kit = let flags = { frozen = true; sealed = Sealed; exact = true } in let x = Nel.one (reason, SMap.empty, Some ({ dict_name = None; + dict_kind = Property.Member ("[string]", loc_of_reason reason); key = StrT.make r; value = t; dict_polarity = Neutral; @@ -11521,8 +11686,8 @@ end = struct | DefT (_, PolyT (_, sub_type, _)) -> (* TODO: replace type parameters with stable/proper names? *) extract_type cx sub_type - | ThisClassT (_, DefT (_, InstanceT (static, _, _, _))) - | DefT (_, ClassT (DefT (_, InstanceT (static, _, _, _)))) -> + | ThisClassT (_, DefT (_, InstanceT (static, _, _, _)), _) + | DefT (_, ClassT (DefT (_, InstanceT (static, _, _, _)), _)) -> let static_t = resolve_type cx static in extract_type cx static_t | DefT (_, FunT _) as t -> @@ -11552,6 +11717,7 @@ end = struct | OpaqueT (_, {super_t = Some t; _}) -> extract_type cx t + | AbstractsT _ | AnyWithLowerBoundT _ | AnyWithUpperBoundT _ | MergedT _ @@ -11595,24 +11761,15 @@ end = struct _}))) -> let members = SMap.fold (fun x p acc -> (* TODO: It isn't currently possible to return two types for a given - * property in autocomplete, so for now we just return the getter - * type. *) - let loc, t = match p with - | Field (loc, t, _) - | Get (loc, t) - | Set (loc, t) - (* arbitrarily use the location for the getter. maybe we can send both in the future *) - | GetSet (loc, t, _, _) - | Method (loc, t) -> - (loc, t) - in - SMap.add x (loc, t) acc + * property in autocomplete, so for now we just arbitrarily choose. + * Maybe we can send both from `GetSet _` in the future. *) + let _, key_loc, t = Property.choose p in + SMap.add x (key_loc, t) acc ) (find_props cx fields) SMap.empty in let members = SMap.fold (fun x p acc -> - match Property.read_t p with - | Some t -> - let loc = Property.read_loc p in - SMap.add x (loc, t) acc + match Property.read p with + | Some (_, key_loc, t) -> + SMap.add x (key_loc, t) acc | None -> acc ) (find_props cx methods) members in let super_t = resolve_type cx super in @@ -11628,10 +11785,9 @@ end = struct let proto_t = resolve_type cx (DefT (proto_reason, IntersectionT rep)) in let prot_members = extract_members_as_map cx proto_t in let members = SMap.fold (fun x p acc -> - match Property.read_t p with - | Some t -> - let loc = Property.read_loc p in - SMap.add x (loc, t) acc + match Property.read p with + | Some (_, key_loc, t) -> + SMap.add x (key_loc, t) acc | None -> acc ) (find_props cx flds) SMap.empty in Success (AugmentableSMap.augment prot_members ~with_bindings:members) @@ -11756,7 +11912,7 @@ let rec assert_ground ?(infer=false) ?(depth=1) cx skip ids t = recurse ~infer:true return_t | DefT (_, PolyT (_, t, _)) - | ThisClassT (_, t) -> + | ThisClassT (_, t, _) -> recurse t | DefT (_, ObjT { props_tmap = id; proto_t; _ }) -> @@ -11775,7 +11931,7 @@ let rec assert_ground ?(infer=false) ?(depth=1) cx skip ids t = recurse ~infer:true elemt; List.iter (recurse ~infer:true) tuple_types - | DefT (_, ClassT t) + | DefT (_, ClassT (t, _)) | DefT (_, TypeT t) -> recurse t @@ -11876,6 +12032,7 @@ let rec assert_ground ?(infer=false) ?(depth=1) cx skip ids t = | InternalT (ReposUpperT (_, t)) -> recurse ~infer:true t + | AbstractsT _ | NullProtoT _ | ObjProtoT _ | FunProtoT _ diff --git a/src/typing/func_sig.ml b/src/typing/func_sig.ml index 36e55a73ba9..410c6b0a483 100644 --- a/src/typing/func_sig.ml +++ b/src/typing/func_sig.ml @@ -26,7 +26,7 @@ type t = { tparams: Type.typeparam list; tparams_map: Type.t SMap.t; fparams: Func_params.t; - body: Loc.t Ast.Function.body; + body: Loc.t Ast.Function.body option; return_t: Type.t; } @@ -73,7 +73,7 @@ let mk cx tparams_map ~expr loc func = ); Anno.mk_type_annotation cx tparams_map ret_reason None ) in - {reason; kind; tparams; tparams_map; fparams; body; return_t} + {reason; kind; tparams; tparams_map; fparams; body = Some body; return_t} let empty_body = let loc = Loc.none in @@ -83,15 +83,19 @@ let empty_body = let convert cx tparams_map loc func = let {Ast.Type.Function.typeParameters; returnType; _} = func in let reason = mk_reason RFunctionType loc in - let kind = Ordinary in + let kind = Ast.Type.Function.(match func.async, func.generator with + | true, false -> Generator + | false, true -> Async + | true, true -> AsyncGenerator + | false, false -> Ordinary + ) in let tparams, tparams_map = Anno.mk_type_param_declarations cx ~tparams_map typeParameters in let fparams = Func_params.convert cx tparams_map func in - let body = empty_body in let return_t = Anno.convert cx tparams_map returnType in - {reason; kind; tparams; tparams_map; fparams; body; return_t} + {reason; kind; tparams; tparams_map; fparams; body = None; return_t} let default_constructor reason = { reason; @@ -99,7 +103,7 @@ let default_constructor reason = { tparams = []; tparams_map = SMap.empty; fparams = Func_params.empty; - body = empty_body; + body = Some empty_body; return_t = VoidT.why reason; } @@ -109,7 +113,7 @@ let field_initializer cx tparams_map reason expr annot = { tparams = []; tparams_map; fparams = Func_params.empty; - body = empty_body; + body = Some empty_body; return_t = Anno.mk_type_annotation cx tparams_map reason annot; } @@ -141,7 +145,8 @@ let generate_tests cx f x = let functiontype cx this_t {reason; kind; tparams; fparams; return_t; _} = let knot = Tvar.mk cx reason in let static = - let props = SMap.singleton "$call" (Method (None, knot)) in + let meth = (Property.Member ("$call", loc_of_reason reason), None, knot) in + let props = SMap.singleton "$call" (Method meth) in let proto = FunProtoT reason in Obj_type.mk_with_proto cx reason ~props proto in @@ -187,6 +192,10 @@ let settertype {fparams; _} = let toplevels id cx this super ~decls ~stmts ~expr {kind; tparams_map; fparams; body; return_t; _} = + match body with + | None -> () + | Some body -> + let loc, reason = let loc = Ast.Function.(match body with | BodyBlock (loc, _) @@ -362,4 +371,12 @@ let toplevels id cx this super ~decls ~stmts ~expr Env.update_env cx loc env +let reason_of_t ({reason; _}:t) = reason + +let replace_reason f (t:t):t = + {t with reason = replace_reason f t.reason} + +let replace_reason_const desc (t:t):t = + {t with reason = replace_reason_const desc t.reason} + let to_ctor_sig f = { f with kind = Ctor } diff --git a/src/typing/func_sig.mli b/src/typing/func_sig.mli index 0ebb1a1c646..a3d9743053a 100644 --- a/src/typing/func_sig.mli +++ b/src/typing/func_sig.mli @@ -102,4 +102,7 @@ val settertype: t -> Type.t (** The location of the return type for a function. *) val return_loc: Loc.t Ast.Function.t -> Loc.t +val reason_of_t: t -> Reason.t +val replace_reason: (Reason.reason_desc -> Reason.reason_desc) -> t -> t +val replace_reason_const: Reason.reason_desc -> t -> t val to_ctor_sig: t -> t diff --git a/src/typing/react_kit.ml b/src/typing/react_kit.ml index b41183decfa..903f4257722 100644 --- a/src/typing/react_kit.ml +++ b/src/typing/react_kit.ml @@ -96,8 +96,8 @@ let run cx trace ~use_op reason_op l u let component_class props = let reason = reason_of_t l in - DefT (reason, ClassT (get_builtin_typeapp cx reason - "React$Component" [props; AnyT.why reason])) + DefT (reason, ClassT (get_builtin_typeapp cx reason "React$Component" + [props; AnyT.why reason], abstracts_type l SMap.empty SMap.empty)) in (* We create our own FunT instead of using @@ -196,7 +196,9 @@ let run cx trace ~use_op reason_op l u rec_flow_t cx trace (component, component_function tin) (* Intrinsic components. *) - | DefT (_, StrT lit) -> get_intrinsic `Props lit (Field (None, tin, Negative)) + | DefT (r, StrT lit) -> + let kind = Property.Explicit (loc_of_reason r) in + get_intrinsic `Props lit (Field ((kind, None, tin), Negative)) (* any and any specializations *) | DefT (reason, (AnyT | AnyObjT | AnyFunT)) -> @@ -226,7 +228,9 @@ let run cx trace ~use_op reason_op l u rec_flow_t cx trace (component_function ~with_return_t:false tout, component) (* Special case for intrinsic components. *) - | DefT (_, StrT lit) -> get_intrinsic `Props lit (Field (None, tout, Positive)) + | DefT (r, StrT lit) -> + let kind = Property.Explicit (loc_of_reason r) in + get_intrinsic `Props lit (Field ((kind, None, tout), Positive)) (* any and any specializations *) | DefT (reason, (AnyT | AnyObjT | AnyFunT)) -> @@ -261,7 +265,11 @@ let run cx trace ~use_op reason_op l u let strict = NonstrictReturning (Some (DefT (reason_missing, VoidT), tvar)) in let propref = Named (reason_prop, name) in - let action = LookupProp (unknown_use, Field (None, tvar, Positive)) in + let action = + let kind = Property.Member (name, loc_of_reason reason_op) in + let field = Field ((kind, None, tvar), Positive) in + LookupProp (unknown_use, field) + in (* Lookup the `defaultProps` property. *) rec_flow cx trace (component, LookupT (reason_op, strict, [], propref, action)) @@ -371,7 +379,10 @@ let run cx trace ~use_op reason_op l u (* Flow the config input key type to the key type. *) let kind = NonstrictReturning None in let propref = Named (reason_key, "key") in - let action = LookupProp (unknown_use, Field (None, key_t, Positive)) in + let action = + let kind = Property.Explicit (loc_of_t config) in + LookupProp (unknown_use, Field ((kind, None, key_t), Positive)) + in rec_flow cx trace (config, LookupT (reason_key, kind, [], propref, action)) in @@ -390,7 +401,10 @@ let run cx trace ~use_op reason_op l u (* Flow the config input ref type to the ref type. *) let kind = NonstrictReturning None in let propref = Named (reason_ref, "ref") in - let action = LookupProp (unknown_use, Field (None, ref_t, Positive)) in + let action = + let kind = Property.Explicit (loc_of_t config) in + LookupProp (unknown_use, Field ((kind, None, ref_t), Positive)) + in rec_flow cx trace (config, LookupT (reason_ref, kind, [], propref, action)) in @@ -463,7 +477,7 @@ let run cx trace ~use_op reason_op l u let component = l in match component with (* Class components or legacy components. *) - | DefT (_, ClassT component) -> rec_flow_t cx trace (component, tout) + | DefT (_, ClassT (component, _)) -> rec_flow_t cx trace (component, tout) (* Stateless functional components. *) | DefT (r, FunT _) -> @@ -474,7 +488,9 @@ let run cx trace ~use_op reason_op l u rec_flow_t cx trace (VoidT.make (replace_reason_const RVoid r), tout) (* Intrinsic components. *) - | DefT (_, StrT lit) -> get_intrinsic `Instance lit (Field (None, tout, Positive)) + | DefT (r, StrT lit) -> + let kind = Property.Explicit (loc_of_reason r) in + get_intrinsic `Instance lit (Field ((kind, None, tout), Positive)) (* any and any specializations *) | DefT (reason, (AnyT | AnyObjT | AnyFunT)) -> @@ -528,6 +544,7 @@ let run cx trace ~use_op reason_op l u let props = SMap.empty in let dict = { dict_name = None; + dict_kind = Property.Explicit Loc.none; key = Locationless.AnyT.t; value; dict_polarity = Neutral; @@ -584,8 +601,8 @@ let run cx trace ~use_op reason_op l u (* TODO: This is _very_ similar to `CreateClass.PropTypes` below, except for reasons descriptions/locations, recursive ReactKit constraints, and `resolve` behavior. *) - let add_prop k t (reason, props, dict, flags) = - let props = SMap.add k (Field (None, t, Neutral)) props in + let add_prop k triple (reason, props, dict, flags) = + let props = SMap.add k (Field (triple, Neutral)) props in reason, props, dict, flags in let add_dict dict (reason, props, _, flags) = @@ -603,12 +620,12 @@ let run cx trace ~use_op reason_op l u resolve t | Some (k, p) -> let todo = SMap.remove k todo in - match Property.read_t p with + match Property.read p with | None -> next todo shape - | Some t -> + | Some (kind, key_loc, t) -> rec_flow cx trace (t, ReactKitT (unknown_use, reason_op, SimplifyPropType (Shape - (ResolveProp (k, todo, shape)), tout))) + (ResolveProp (k, kind, key_loc, todo, shape)), tout))) in (match tool with | ResolveObject -> @@ -633,12 +650,12 @@ let run cx trace ~use_op reason_op l u | Error reason -> {dicttype with value = DefT (reason, AnyT)} in next todo (add_dict dict shape) - | ResolveProp (k, todo, shape) -> + | ResolveProp (k, kind, key_loc, todo, shape) -> let t = match coerce_prop_type l with | Ok (required, t) -> if required then t else Type.optional t | Error _ -> Type.optional (DefT (reason_op, AnyT)) in - next todo (add_prop k t shape)) + next todo (add_prop k (kind, key_loc, t) shape)) in let create_class knot tout = @@ -658,9 +675,9 @@ let run cx trace ~use_op reason_op l u match SMap.get x props with | Some _ as p -> p | None -> - Option.map dict (fun { key; value; dict_polarity; _ } -> + Option.map dict (fun { dict_kind; key; value; dict_polarity; _ } -> rec_flow_t cx trace (string_key x reason_op, key); - Field (None, value, dict_polarity)) + Field ((dict_kind, None, value), dict_polarity)) in let read_prop x obj = Option.bind (get_prop x obj) Property.read_t in @@ -840,10 +857,12 @@ let run cx trace ~use_op reason_op l u mod_reason_of_t (replace_reason_const RReactPropTypes) props_t in + let props_kind = Property.Member ("props", loc_of_reason reason_op) in + let state_kind = Property.Member ("state", loc_of_reason reason_op) in let props = SMap.empty - |> SMap.add "props" (Field (None, props_t, Neutral)) - |> SMap.add "state" (Field (None, knot.state_t, Neutral)) + |> SMap.add "props" (Field ((props_kind, None, props_t), Neutral)) + |> SMap.add "state" (Field ((state_kind, None, knot.state_t), Neutral)) in (* Some spec fields are used to create the instance type, but are not @@ -877,10 +896,9 @@ let run cx trace ~use_op reason_op l u | "componentDidUpdate" | "componentWillUnmount" | "updateComponent" -> - let loc = Property.read_loc v in - let v = match Property.read_t v with + let v = match Property.read v with | None -> v - | Some t -> + | Some ((_, _, t) as triple) -> (* Tie the `this` knot with BindT *) let dummy_return = DefT (reason_op, AnyT) in let calltype = mk_methodcalltype knot.this [] dummy_return in @@ -889,7 +907,7 @@ let run cx trace ~use_op reason_op l u upper bound (e.g., as a super class), it's more flexible to create covariant methods. Otherwise, a subclass could not override the `render` method, say. *) - Method (loc, t) + Method triple in SMap.add k v props, static_props @@ -904,8 +922,11 @@ let run cx trace ~use_op reason_op l u SMap.add k bound_v props, static_props ) spec_props (props, SMap.empty) in - let static_props = static_props - |> SMap.add "defaultProps" (Field (None, knot.default_t, Neutral)) + let static_props = + let name = "defaultProps" in + let kind = Property.Member (name, loc_of_t knot.default_t) in + let field = Field ((kind, None, knot.default_t), Neutral) in + SMap.add name field static_props in let reason_component = replace_reason_const RReactComponent reason_op in @@ -923,6 +944,7 @@ let run cx trace ~use_op reason_op l u | Some (Unknown reason) -> let dict = Some { dict_name = None; + dict_kind = Property.Member ("[string]", loc_of_reason reason); key = StrT.why reason; value = AnyT.why reason; dict_polarity = Neutral; @@ -934,7 +956,7 @@ let run cx trace ~use_op reason_op l u reason, static_props, dict, exact, sealed in let reason = replace_reason_const RReactStatics reason in - Obj_type.mk_with_proto cx reason ~props (class_type super) + Obj_type.mk_with_proto cx reason ~props (nonabstract_class_type super) ?dict ~exact ~sealed in @@ -954,7 +976,7 @@ let run cx trace ~use_op reason_op l u let instance = DefT (reason_component, InstanceT (static, super, [], insttype)) in rec_flow_t cx trace (instance, knot.this); rec_flow_t cx trace (static, knot.static); - rec_flow_t cx trace (class_type instance, tout) + rec_flow_t cx trace (nonabstract_class_type instance, tout) in let empty_spec obj = { @@ -1021,8 +1043,8 @@ let run cx trace ~use_op reason_op l u }) stack |> on_resolve_statics | PropTypes (stack, tool) -> - let add_prop k t (reason, props, dict, flags) = - let props = SMap.add k (Field (None, t, Neutral)) props in + let add_prop k triple (reason, props, dict, flags) = + let props = SMap.add k (Field (triple, Neutral)) props in reason, props, dict, flags in let add_dict dict (reason, props, _, flags) = @@ -1038,11 +1060,11 @@ let run cx trace ~use_op reason_op l u }) stack |> on_resolve_prop_types | Some (k, p) -> let todo = SMap.remove k todo in - match Property.read_t p with + match Property.read p with | None -> next todo prop_types - | Some t -> + | Some (kind, key_loc, t) -> let tool = PropTypes (stack, - ResolveProp (k, todo, prop_types)) in + ResolveProp (k, kind, key_loc, todo, prop_types)) in resolve tool t in (match tool with @@ -1073,12 +1095,12 @@ let run cx trace ~use_op reason_op l u | Error reason -> {dicttype with value = DefT (reason, AnyT)} in next todo (add_dict dict prop_types) - | ResolveProp (k, todo, prop_types) -> + | ResolveProp (k, kind, key_loc, todo, prop_types) -> let t = match coerce_prop_type l with | Ok (required, t) -> if required then t else Type.optional t | Error reason -> Type.optional (DefT (reason, AnyT)) in - next todo (add_prop k t prop_types)) + next todo (add_prop k (kind, key_loc, t) prop_types)) | DefaultProps (todo, acc) -> let default_props = Some (maybe_known_of_result (coerce_object l)) in diff --git a/src/typing/sigHash.ml b/src/typing/sigHash.ml index 7a426f10f49..a7d707cf6f7 100644 --- a/src/typing/sigHash.ml +++ b/src/typing/sigHash.ml @@ -59,6 +59,7 @@ type hash = | TypeAppH | ThisClassH | ThisTypeAppH + | AbstractsH | BoundH | ExistsH | ExactH @@ -96,6 +97,7 @@ type hash = | GetElemH | CallElemH | GetStaticsH + | AssertNonabstractH | GetProtoH | SetProtoH | ReposLowerH @@ -104,6 +106,7 @@ type hash = | SuperH | ImplementsH | MixinH + | AccAbstractsH | AdderH | ComparatorH | UnaryMinusH @@ -230,6 +233,7 @@ let hash_of_ctor = Type.(function | ShapeT _ -> ShapeH | ThisClassT _ -> ThisClassH | ThisTypeAppT _ -> ThisTypeAppH + | AbstractsT _ -> AbstractsH ) let hash_of_use_ctor = Type.(function @@ -247,6 +251,7 @@ let hash_of_use_ctor = Type.(function | GetElemT _ -> GetElemH | CallElemT _ -> CallElemH | GetStaticsT _ -> GetStaticsH + | AssertNonabstractT _ -> AssertNonabstractH | GetProtoT _ -> GetProtoH | SetProtoT _ -> SetProtoH | ReposLowerT _ -> ReposLowerH @@ -255,6 +260,7 @@ let hash_of_use_ctor = Type.(function | SuperT _ -> SuperH | ImplementsT _ -> ImplementsH | MixinT _ -> MixinH + | AccAbstractsT _ -> AccAbstractsH | AdderT _ -> AdderH | ComparatorT _ -> ComparatorH | UnaryMinusT _ -> UnaryMinusH @@ -368,13 +374,14 @@ let add_reason state r = let add_polarity = add_int let add_prop state = Type.(function - | Field (_, _, polarity) -> + | Field (_, polarity) -> add_int state 0; add_int state polarity | Get _ -> add_int state 1 | Set _ -> add_int state 2 | GetSet _ -> add_int state 3 | Method _ -> add_int state 4 + | Abstract _ -> add_int state 5 ) let add_props_map state = diff --git a/src/typing/statement.ml b/src/typing/statement.ml index 54a5ed1f177..b6f8bbac715 100644 --- a/src/typing/statement.ml +++ b/src/typing/statement.ml @@ -1564,8 +1564,9 @@ and statement cx = Ast.Statement.( let props = SMap.fold (fun x entry acc -> match entry with | Value {specific; _} -> - let loc = Some (entry_loc entry) in - Properties.add_field x Neutral loc specific acc + let loc = entry_loc entry in + let kind = Property.Explicit loc in + Properties.add_field x (kind, Some loc, specific) Neutral acc | Type _ | Class _ -> acc ) module_scope.entries SMap.empty in let proto = ObjProtoT reason in @@ -1594,8 +1595,6 @@ and statement cx = Ast.Statement.( Context.set_module_kind cx outer_module_exports_kind; Env.pop_var_scope (); - - | (loc, DeclareExportDeclaration { DeclareExportDeclaration.default; DeclareExportDeclaration.declaration; @@ -2084,19 +2083,20 @@ and export_statement cx loc and object_prop cx map = Ast.Expression.Object.(function (* named prop *) - | Property (_, Property.Init { + | Property (prop_loc, Property.Init { key = Property.Identifier (loc, name) | Property.Literal (loc, { Ast.Literal.value = Ast.Literal.String name; _; }); - value = v; _ }) -> - let t = expression cx v in - Properties.add_field name Neutral (Some loc) t map + value; _ }) -> + let t = expression cx value in + let fld = (Type.Property.Explicit prop_loc, Some loc, t) in + Properties.add_field name fld Neutral map (* named method *) - | Property (_, Property.Method { + | Property (prop_loc, Property.Method { key = Property.Identifier (loc, name) | Property.Literal (loc, { @@ -2106,7 +2106,8 @@ and object_prop cx map = Ast.Expression.Object.(function value = (fn_loc, func); }) -> let t = expression cx (fn_loc, Ast.Expression.Function func) in - Properties.add_field name Neutral (Some loc) t map + let fld = (Type.Property.Explicit prop_loc, Some loc, t) in + Properties.add_field name fld Neutral map (* We enable some unsafe support for getters and setters. The main unsafe bit * is that we don't properly havok refinements when getter and setter methods @@ -2125,7 +2126,8 @@ and object_prop cx map = Ast.Expression.Object.(function Flow_js.add_output cx (Flow_error.EUnsafeGettersSetters loc); let function_type = mk_function None cx vloc func in let return_t = Type.extract_getter_type function_type in - Properties.add_getter name (Some id_loc) return_t map + let get = (Type.Property.Explicit loc, Some id_loc, return_t) in + Properties.add_getter name get map (* unsafe setter property *) | Property (loc, Property.Set { @@ -2140,7 +2142,8 @@ and object_prop cx map = Ast.Expression.Object.(function Flow_js.add_output cx (Flow_error.EUnsafeGettersSetters loc); let function_type = mk_function None cx vloc func in let param_t = Type.extract_setter_type function_type in - Properties.add_setter name (Some id_loc) param_t map + let set = (Type.Property.Explicit loc, Some id_loc, param_t) in + Properties.add_setter name set map (* literal LHS *) | Property (loc, Property.Init { key = Property.Literal _; _ }) @@ -2487,12 +2490,13 @@ and expression_ ~is_cond cx loc e = Ast.Expression.(match e with let prop_reason = mk_reason (RProperty (Some name)) ploc in let super = super_ cx super_loc in + let use_op = Op (GetProperty prop_reason) in + assert_nonabstract cx prop_reason ~use_op super name; if Type_inference_hooks_js.dispatch_member_hook cx name ploc super then AnyT.at ploc else ( Tvar.mk_where cx expr_reason (fun tvar -> - let use_op = Op (GetProperty prop_reason) in Flow.flow cx ( super, GetPropT (use_op, expr_reason, Named (prop_reason, name), tvar) ) @@ -2699,6 +2703,12 @@ and expression_ ~is_cond cx loc e = Ast.Expression.(match e with let reason_prop = mk_reason (RProperty (Some name)) ploc in let super = super_ cx super_loc in let argts = List.map (expression_or_spread cx) arguments in + let use_op = Op (FunCallMethod { + op=reason; + fn=mk_reason (RMethod (Some name)) callee_loc; + prop=reason_prop; + }) in + assert_nonabstract cx reason ~use_op super name; Type_inference_hooks_js.dispatch_call_hook cx name ploc super; Tvar.mk_where cx reason (fun t -> let funtype = mk_methodcalltype super argts t in @@ -3793,7 +3803,7 @@ and jsx_mk_props cx reason c name attributes children = Ast.JSX.( | None -> DefT (mk_reason RBoolean aloc, BoolT (Some true)) in - let p = Field (Some id_loc, atype, Neutral) in + let p = Field ((Property.Explicit aloc, Some id_loc, atype), Neutral) in (sealed, SMap.add aname p map, result) (* Do nothing for namespaced attributes or ignored React attributes. *) | Opening.Attribute _ -> @@ -3822,7 +3832,8 @@ and jsx_mk_props cx reason c name attributes children = Ast.JSX.( children (ResolveSpreadsToArrayLiteral (mk_id (), tout)) ) in - let p = Field (None, arr, Neutral) in + let kind = Property.Explicit (loc_of_reason reason) in + let p = Field ((kind, None, arr), Neutral) in SMap.add "children" p map in eval_props ~sealed (map, result) @@ -3964,6 +3975,19 @@ and jsx_title_member_to_expression member = }) ) +and assert_nonabstract cx reason ~use_op super name = + let super, static = match super with + | DefT (_, VoidT) -> super, false + | ThisTypeAppT _ -> super, false + | DefT (_, ClassT (s, _)) -> s, true + | _ -> failwith "Unexpected super type" + in + let assertion = + let kind = NonabstractMember (static, name) in + AssertNonabstractT (use_op, reason, kind) + in + Flow.flow cx (super, assertion) + (* Given an expression found in a test position, notices certain type refinements which follow from the test's success or failure, and returns a quad: @@ -4535,8 +4559,7 @@ and static_method_call_Object cx loc prop_loc expr obj_t m args_ = in let pmap = prop_map_of_object cx properties in let props = SMap.fold (fun x p acc -> - let loc = Property.read_loc p in - match Property.read_t p with + match Property.read p with | None -> (* Since the properties object must be a literal, and literal objects can only ever contain neutral fields, this should not happen. *) @@ -4544,14 +4567,14 @@ and static_method_call_Object cx loc prop_loc expr obj_t m args_ = EInternal (prop_loc, PropertyDescriptorPropertyCannotBeRead) ); acc - | Some spec -> + | Some (kind, key_loc, spec) -> let reason = replace_reason (fun desc -> RCustom (spf ".%s of %s" x (string_of_desc desc)) ) reason in let t = Tvar.mk_where cx reason (fun tvar -> Flow.flow cx (spec, GetPropT (unknown_use, reason, Named (reason, "value"), tvar)) ) in - let p = Field (loc, t, Neutral) in + let p = Field ((kind, key_loc, t), Neutral) in SMap.add x p acc ) pmap SMap.empty in Obj_type.mk_with_proto cx reason ~props proto @@ -4654,7 +4677,7 @@ and mk_class cx loc reason c = ~expr:expression ); let class_t = Class_sig.classtype cx class_sig in - Flow.unify cx self class_t; + Flow.unify cx self class_t; (*Self needs a nonabstract version, no?*) class_t (* Given a function declaration and types for `this` and `super`, extract a @@ -4721,10 +4744,12 @@ and declare_function_to_function_declaration cx id typeAnnotation predicate = | Some (loc, Ast.Type.Predicate.Declared e) -> begin match typeAnnotation with - | (_, (_, Ast.Type.Function - { Ast.Type.Function.params = (params_loc, { Ast.Type.Function.Params.params; rest }); - Ast.Type.Function.returnType; - Ast.Type.Function.typeParameters; + | (_, (_, Ast.Type.Function { Ast.Type.Function. + params = (params_loc, { Ast.Type.Function.Params.params; rest }); + async = false; + generator = false; + returnType; + typeParameters; })) -> let param_type_to_param = Ast.Type.Function.( fun (l, { Param.name; Param.typeAnnotation; _ }) -> diff --git a/src/typing/type.ml b/src/typing/type.ml index 25bfecb13c0..a187373c1b0 100644 --- a/src/typing/type.ml +++ b/src/typing/type.ml @@ -76,9 +76,10 @@ module rec TypeTerm : sig | ExistsT of reason (* this-abstracted class *) - | ThisClassT of reason * t + | ThisClassT of reason * t * t (* this instantiation *) | ThisTypeAppT of reason * t * t * t list option + | AbstractsT of reason * (abstracts * abstracts) (* exact *) | ExactT of reason * t @@ -202,7 +203,7 @@ module rec TypeTerm : sig | ObjT of objtype | ArrT of arrtype (* type of a class *) - | ClassT of t + | ClassT of t * t (* type of an instance of a class *) | InstanceT of static * super * implements * insttype (* singleton string, matches exactly a given string literal *) @@ -358,6 +359,7 @@ module rec TypeTerm : sig | GetElemT of use_op * reason * t * t | CallElemT of (* call *) reason * (* lookup *) reason * t * funcalltype | GetStaticsT of reason * t_out + | AssertNonabstractT of use_op * reason * nonabstract | GetProtoT of reason * t_out | SetProtoT of reason * t @@ -370,8 +372,9 @@ module rec TypeTerm : sig | ConstructorT of use_op * reason * call_arg list * t | SuperT of use_op * reason * derived_type | ImplementsT of use_op * t - | MixinT of reason * t + | MixinT of use_op * reason * t | ToStringT of reason * t + | AccAbstractsT of reason * (SSet.t * SSet.t) * (abstracts * abstracts) * t (* overloaded +, could be subsumed by general overloading *) | AdderT of reason * bool * t * t @@ -840,6 +843,7 @@ module rec TypeTerm : sig and dicttype = { dict_name: string option; + dict_kind: Property.kind; key: t; value: t; dict_polarity: polarity; @@ -847,13 +851,13 @@ module rec TypeTerm : sig and polarity = Negative | Neutral | Positive - (* Locations refer to the location of the identifier, if one exists *) and property = - | Field of Loc.t option * t * polarity - | Get of Loc.t option * t - | Set of Loc.t option * t - | GetSet of Loc.t option * t * Loc.t option * t - | Method of Loc.t option * t + | Field of Property.triple * polarity + | Get of Property.triple + | Set of Property.triple + | GetSet of Property.triple * Property.triple + | Method of Property.triple + | Abstract of Property.triple (* This has to go here so that Type doesn't depend on Scope *) and class_binding = { @@ -958,6 +962,12 @@ module rec TypeTerm : sig and implements = t list + and abstracts = reason SMap.t + + and nonabstract = + | NonabstractMember of bool (* static *) * string + | NonabstractClass + and t_out = t and custom_fun_kind = @@ -1121,14 +1131,24 @@ end and Property : sig type t = TypeTerm.property + (* Locations refer to the location of the identifier, if one exists *) + type triple = kind * Loc.t option * TypeTerm.t + + and kind = + | Explicit of Loc.t (* The location of the identifier and its value *) + | Member of string * Loc.t (* The location of the property's container *) + | Custom of string * Loc.t + val polarity: t -> Polarity.t + val choose: t -> triple + val read: t -> triple option + val write: ?ctx:TypeTerm.write_ctx -> t -> triple option val read_t: t -> TypeTerm.t option val write_t: ?ctx:TypeTerm.write_ctx -> t -> TypeTerm.t option val access: TypeTerm.rw -> t -> TypeTerm.t option - val read_loc: t -> Loc.t option - val write_loc: t -> Loc.t option + val iter_reason: (reason -> unit) -> t -> unit val iter_t: (TypeTerm.t -> unit) -> t -> unit val fold_t: ('a -> TypeTerm.t -> 'a) -> 'a -> t -> 'a @@ -1142,104 +1162,120 @@ end = struct type t = property + type triple = kind * Loc.t option * TypeTerm.t + + and kind = + | Explicit of Loc.t + | Member of string * Loc.t + | Custom of string * Loc.t + + let triples = function + | Field (triple, _) + | Get triple + | Set triple + | Method triple + | Abstract triple -> + Nel.one triple + | GetSet (get, set) -> + Nel.cons get (Nel.one set) + + let third (_, _, t) = t + let polarity = function - | Field (_, _, polarity) -> polarity + | Field (_, polarity) -> polarity | Get _ -> Positive | Set _ -> Negative | GetSet _ -> Neutral | Method _ -> Positive + | Abstract _ -> Positive - let read_t = function - | Field (_, t, polarity) -> + let choose = Fn.compose Nel.hd triples + + let read = function + | Field (triple, polarity) -> if Polarity.compat (polarity, Positive) - then Some t + then Some triple else None - | Get (_, t) -> Some t + | Get triple -> Some triple | Set _ -> None - | GetSet (_, t, _, _) -> Some t - | Method (_, t) -> Some t + | GetSet (triple, _) -> Some triple + | Method triple -> Some triple + | Abstract triple -> Some triple - let write_t ?(ctx=Normal) = function - | Field (_, t, _) when ctx = ThisInCtor -> Some t - | Field (_, t, polarity) -> + let write ?(ctx=Normal) = function + | Field (triple, _) when ctx = ThisInCtor -> Some triple + | Field (triple, polarity) -> if Polarity.compat (polarity, Negative) - then Some t + then Some triple else None | Get _ -> None - | Set (_, t) -> Some t - | GetSet (_, _, _, t) -> Some t + | Set triple -> Some triple + | GetSet (_, triple) -> Some triple | Method _ -> None - - let read_loc = function - | Field (loc, _, _) - | Get (loc, _) - | GetSet (loc, _, _, _) - | Method (loc, _) -> - loc - | Set _ -> None - - let write_loc = function - | Field (loc, _, _) - | Set (loc, _) - | GetSet (_, _, loc, _) -> - loc - | Method _ - | Get _ -> - None + | Abstract _ -> None + + let read_t = Fn.compose (Option.map ~f:third) read + let write_t ?(ctx=Normal) = Fn.compose (Option.map ~f:third) (write ~ctx) + + let kind_reason explicit_desc = function + | Explicit loc -> mk_reason (RPropertyDef explicit_desc) loc + | Member (name, loc) -> mk_reason (RMember name) loc + | Custom (msg, loc) -> mk_reason (RCustom msg) loc + + let iter_reason f = function + | Field ((kind, _, _), _) -> f (kind_reason RFieldDef kind) + | Get (kind, _, _) -> f (kind_reason RGetterDef kind) + | Set (kind, _, _) -> f (kind_reason RSetterDef kind) + | GetSet ((get_kind, _, _), (set_kind, _, _)) -> + f (kind_reason RGetterDef get_kind); + f (kind_reason RSetterDef set_kind) + | Method (kind, _, _) -> f (kind_reason RMethodDef kind) + | Abstract (kind, _, _) -> f (kind_reason RAbstractMethodDef kind) let access = function | Read -> read_t | Write (ctx, _) -> write_t ~ctx - let iter_t f = function - | Field (_, t, _) - | Get (_, t) - | Set (_, t) - | Method (_, t) -> - f t - | GetSet (_, t1, _, t2) -> - f t1; - f t2 - - let fold_t f acc = function - | Field (_, t, _) - | Get (_, t) - | Set (_, t) - | Method (_, t) -> - f acc t - | GetSet (_, t1, _, t2) -> - f (f acc t1) t2 + let ts = Fn.compose (Nel.map third) triples + let iter_t f = Fn.compose (Nel.iter f) ts + let fold_t f acc = Fn.compose (Nel.fold_left f acc) ts let map_t f = function - | Field (loc, t, polarity) -> Field (loc, f t, polarity) - | Get (loc, t) -> Get (loc, f t) - | Set (loc, t) -> Set (loc, f t) - | GetSet (loc1, t1, loc2, t2) -> GetSet (loc1, f t1, loc2, f t2) - | Method (loc, t) -> Method (loc, f t) + | Field ((kind, key_loc, t), polarity) -> Field ((kind, key_loc, f t), polarity) + | Get (kind, key_loc, t) -> Get (kind, key_loc, f t) + | Set (kind, key_loc, t) -> Set (kind, key_loc, f t) + | GetSet ((kind1, key_loc1, t1), (kind2, key_loc2, t2)) -> + GetSet ((kind1, key_loc1, f t1), (kind2, key_loc2, f t2)) + | Method (kind, key_loc, t) -> Method (kind, key_loc, f t) + | Abstract (kind, key_loc, t) -> Abstract (kind, key_loc, f t) let ident_map_t f p = match p with - | Field (loc, t, polarity) -> + | Field ((kind, key_loc, t), polarity) -> let t_ = f t in - if t_ == t then p else Field (loc, t_, polarity) - | Get (loc, t) -> + if t_ == t then p else Field ((kind, key_loc, t_), polarity) + | Get (kind, key_loc, t) -> let t_ = f t in - if t_ == t then p else Get (loc, t_) - | Set (loc, t) -> + if t_ == t then p else Get (kind, key_loc, t_) + | Set (kind, key_loc, t) -> let t_ = f t in - if t_ == t then p else Set (loc, t_) - | GetSet (loc1, t1, loc2, t2) -> + if t_ == t then p else Set (kind, key_loc, t_) + | GetSet ((kind1, key_loc1, t1), (kind2, key_loc2, t2)) -> let t1_ = f t1 in let t2_ = f t2 in - if t1_ == t1 && t2_ == t2 then p else GetSet (loc1, t1_, loc2, t2_) - | Method (loc, t) -> + if t1_ == t1 && t2_ == t2 then p + else GetSet ((kind1, key_loc1, t1_), (kind2, key_loc2, t2_)) + | Method (kind, key_loc, t) -> + let t_ = f t in + if t_ == t then p else Method (kind, key_loc, t_) + | Abstract (kind, key_loc, t) -> let t_ = f t in - if t_ == t then p else Method (loc, t_) + if t_ == t then p else Abstract (kind, key_loc, t_) let forall_t f = fold_t (fun acc t -> acc && f t) true let assert_field = function - | Field (_, t, _) -> t + | Field ((_, _, t), _) -> t | _ -> assert_false "Unexpected field type" end @@ -1250,10 +1286,11 @@ and Properties : sig module Map : MyMap.S with type key = id type map = t Map.t - val add_field: string -> Polarity.t -> Loc.t option -> TypeTerm.t -> t -> t - val add_getter: string -> Loc.t option -> TypeTerm.t -> t -> t - val add_setter: string -> Loc.t option -> TypeTerm.t -> t -> t - val add_method: string -> Loc.t option -> TypeTerm.t -> t -> t + val add_field: string -> Property.triple -> Polarity.t -> t -> t + val add_getter: string -> Property.triple -> t -> t + val add_setter: string -> Property.triple -> t -> t + val add_method: string -> Property.triple -> t -> t + val add_abstract: string -> Property.triple -> t -> t val mk_id: unit -> id val fake_id: id @@ -1278,25 +1315,28 @@ end = struct end) type map = t Map.t - let add_field x polarity loc t = - SMap.add x (Field (loc, t, polarity)) + let add_field x fld polarity = + SMap.add x (Field (fld, polarity)) - let add_getter x loc get_t map = + let add_getter x get map = let p = match SMap.get x map with - | Some (Set (set_loc, set_t)) -> GetSet (loc, get_t, set_loc, set_t) - | _ -> Get (loc, get_t) + | Some (Set set) -> GetSet (get, set) + | _ -> Get get in SMap.add x p map - let add_setter x loc set_t map = + let add_setter x set map = let p = match SMap.get x map with - | Some (Get (get_loc, get_t)) -> GetSet (get_loc, get_t, loc, set_t) - | _ -> Set (loc, set_t) + | Some (Get get) -> GetSet (get, set) + | _ -> Set set in SMap.add x p map - let add_method x loc t = - SMap.add x (Method (loc, t)) + let add_method x meth = + SMap.add x (Method meth) + + let add_abstract x ameth = + SMap.add x (Abstract ameth) let mk_id = Reason.mk_id let fake_id = 0 @@ -1314,12 +1354,12 @@ end = struct let map_t f = SMap.map (Property.map_t f) let map_fields f = SMap.map (function - | Field (loc, t, polarity) -> Field (loc, f t, polarity) + | Field ((kind, key_loc, t), polarity) -> Field ((kind, key_loc, f t), polarity) | p -> p ) let mapi_fields f = SMap.mapi (fun k -> function - | Field (loc, t, polarity) -> Field (loc, f k t, polarity) + | Field ((kind, key_loc, t), polarity) -> Field ((kind, key_loc, f k t), polarity) | p -> p ) end @@ -1595,7 +1635,7 @@ and Object : sig and slice = reason * props * dict * TypeTerm.flags and props = prop SMap.t - and prop = TypeTerm.t * bool (* own *) + and prop = Property.kind * TypeTerm.t * bool (* own *) and dict = TypeTerm.dicttype option @@ -1662,7 +1702,7 @@ and React : sig type resolve_object = | ResolveObject | ResolveDict of (TypeTerm.dicttype * Properties.t * resolved_object) - | ResolveProp of (string * Properties.t * resolved_object) + | ResolveProp of (string * Property.kind * Loc.t option * Properties.t * resolved_object) type resolve_array = | ResolveArray @@ -1765,6 +1805,7 @@ end = struct let rec reason_of_t = function | OpenT (reason,_) -> reason + | AbstractsT (reason, _) -> reason | AnnotT ((reason, _), _) -> reason | AnyWithLowerBoundT (t) -> reason_of_t t | AnyWithUpperBoundT (t) -> reason_of_t t @@ -1793,7 +1834,7 @@ end = struct | ReposT (reason, _) -> reason | InternalT (ReposUpperT (reason, _)) -> reason (* HUH? cf. mod_reason below *) | ShapeT (t) -> reason_of_t t - | ThisClassT (reason, _) -> reason + | ThisClassT (reason, _, _) -> reason | ThisTypeAppT (reason, _, _, _) -> reason and reason_of_defer_use_t = function @@ -1803,6 +1844,7 @@ end = struct and reason_of_use_t = function | UseT (_, t) -> reason_of_t t + | AccAbstractsT (reason, _, _, _) -> reason | AdderT (reason,_,_,_) -> reason | AndT (reason, _, _) -> reason | ArrRestT (_, reason, _, _) -> reason @@ -1810,6 +1852,7 @@ end = struct | AssertBinaryInLHST reason -> reason | AssertBinaryInRHST reason -> reason | AssertForInRHST reason -> reason + | AssertNonabstractT (_, reason, _) -> reason | AssertRestParamT reason -> reason | AssertImportIsValueT (reason, _) -> reason | BecomeT (reason, _) -> reason @@ -1854,7 +1897,7 @@ end = struct | MakeExactT (reason, _) -> reason | MapTypeT (reason, _, _) -> reason | MethodT (_,reason,_,_,_,_) -> reason - | MixinT (reason, _) -> reason + | MixinT (_, reason, _) -> reason | NotT (reason, _) -> reason | ObjAssignToT (reason, _, _, _) -> reason | ObjAssignFromT (reason, _, _, _) -> reason @@ -1908,6 +1951,7 @@ end = struct (* TODO make a type visitor *) let rec mod_reason_of_t f = function | OpenT (reason, id) -> OpenT (f reason, id) + | AbstractsT (reason, abstracts) -> AbstractsT (f reason, abstracts) | AnnotT ((reason, id), use_desc) -> AnnotT ((f reason, id), use_desc) | AnyWithLowerBoundT t -> AnyWithLowerBoundT (mod_reason_of_t f t) | AnyWithUpperBoundT t -> AnyWithUpperBoundT (mod_reason_of_t f t) @@ -1938,7 +1982,7 @@ end = struct | ReposT (reason, t) -> ReposT (f reason, t) | InternalT (ReposUpperT (reason, t)) -> InternalT (ReposUpperT (reason, mod_reason_of_t f t)) | ShapeT t -> ShapeT (mod_reason_of_t f t) - | ThisClassT (reason, t) -> ThisClassT (f reason, t) + | ThisClassT (reason, t, abstracts) -> ThisClassT (f reason, t, abstracts) | ThisTypeAppT (reason, t1, t2, t3) -> ThisTypeAppT (f reason, t1, t2, t3) and mod_reason_of_defer_use_t f = function @@ -1947,6 +1991,8 @@ end = struct and mod_reason_of_use_t f = function | UseT (_, t) -> UseT (Op UnknownUse, mod_reason_of_t f t) + | AccAbstractsT (reason, masks, local_abstracts, t) -> + AccAbstractsT (f reason, masks, local_abstracts, t) | AdderT (reason, flip, rt, lt) -> AdderT (f reason, flip, rt, lt) | AndT (reason, t1, t2) -> AndT (f reason, t1, t2) | ArrRestT (use_op, reason, i, t) -> ArrRestT (use_op, f reason, i, t) @@ -1954,6 +2000,8 @@ end = struct | AssertBinaryInLHST reason -> AssertBinaryInLHST (f reason) | AssertBinaryInRHST reason -> AssertBinaryInRHST (f reason) | AssertForInRHST reason -> AssertForInRHST (f reason) + | AssertNonabstractT (use_op, reason, nonabstract) -> + AssertNonabstractT (use_op, f reason, nonabstract) | AssertRestParamT reason -> AssertRestParamT (f reason) | AssertImportIsValueT (reason, name) -> AssertImportIsValueT (f reason, name) | BecomeT (reason, t) -> BecomeT (f reason, t) @@ -2012,7 +2060,7 @@ end = struct | MapTypeT (reason, kind, t) -> MapTypeT (f reason, kind, t) | MethodT (use_op, reason_call, reason_lookup, name, ft, tm) -> MethodT (use_op, f reason_call, reason_lookup, name, ft, tm) - | MixinT (reason, inst) -> MixinT (f reason, inst) + | MixinT (use_op, reason, inst) -> MixinT (use_op, f reason, inst) | NotT (reason, t) -> NotT (f reason, t) | ObjAssignToT (reason, t, t2, kind) -> ObjAssignToT (f reason, t, t2, kind) @@ -2063,6 +2111,7 @@ end = struct in match u with | UseT (op, t) -> util op (fun op -> UseT (op, t)) + | AssertNonabstractT (op, r, n) -> util op (fun op -> AssertNonabstractT (op, r, n)) | BindT (op, r, f, b) -> util op (fun op -> BindT (op, r, f, b)) | CallT (op, r, f) -> util op (fun op -> CallT (op, r, f)) | MethodT (op, r1, r2, p, f, tm) -> util op (fun op -> MethodT (op, r1, r2, p, f, tm)) @@ -2079,6 +2128,7 @@ end = struct | ConstructorT (op, r, c, t) -> util op (fun op -> ConstructorT (op, r, c, t)) | SuperT (op, r, i) -> util op (fun op -> SuperT (op, r, i)) | ImplementsT (op, t) -> util op (fun op -> ImplementsT (op, t)) + | MixinT (op, r, t) -> util op (fun op -> MixinT (op, r, t)) | SpecializeT (op, r1, r2, c, ts, t) -> util op (fun op -> SpecializeT (op, r1, r2, c, ts, t)) | TypeAppVarianceCheckT (op, r1, r2, ts) -> util op (fun op -> TypeAppVarianceCheckT (op, r1, r2, ts)) @@ -2255,6 +2305,7 @@ let primitive_promoting_use_t = function (* Use types trapped for any propagation *) let any_propagating_use_t = function + | AccAbstractsT _ | AdderT _ | AndT _ | ArrRestT _ @@ -2330,6 +2381,7 @@ let any_propagating_use_t = function | AssertBinaryInRHST _ | AssertForInRHST _ | AssertImportIsValueT _ + | AssertNonabstractT _ | AssertRestParamT _ | ComparatorT _ | DebugPrintT _ @@ -2454,6 +2506,7 @@ let string_of_def_ctor = function let string_of_ctor = function | OpenT _ -> "OpenT" + | AbstractsT _ -> "AbstractsT" | AnnotT _ -> "AnnotT" | AnyWithLowerBoundT _ -> "AnyWithLowerBoundT" | AnyWithUpperBoundT _ -> "AnyWithUpperBoundT" @@ -2540,6 +2593,7 @@ let string_of_use_op_rec = let string_of_use_ctor = function | UseT (op, t) -> spf "UseT(%s, %s)" (string_of_use_op op) (string_of_ctor t) + | AccAbstractsT _ -> "AccAbstractsT" | AdderT _ -> "AdderT" | AndT _ -> "AndT" | ArrRestT _ -> "ArrRestT" @@ -2548,6 +2602,7 @@ let string_of_use_ctor = function | AssertBinaryInRHST _ -> "AssertBinaryInRHST" | AssertForInRHST _ -> "AssertForInRHST" | AssertImportIsValueT _ -> "AssertImportIsValueT" + | AssertNonabstractT _ -> "AssertNonabstractT" | AssertRestParamT _ -> "AssertRestParamT" | BecomeT _ -> "BecomeT" | BindT _ -> "BindT" @@ -2736,13 +2791,25 @@ let maybe t = let exact t = ExactT (reason_of_t t, t) -let class_type t = +let abstracts_type t statics nonstatics = + let reason = replace_reason (fun desc -> RAbstractsOf desc) (reason_of_t t) in + AbstractsT (reason, (statics, nonstatics)) + +let class_type t abstracts = let reason = replace_reason (fun desc -> RStatics desc) (reason_of_t t) in - DefT (reason, ClassT t) + DefT (reason, ClassT (t, abstracts)) -let this_class_type t = +let nonabstract_class_type t = + let abstracts = abstracts_type t SMap.empty SMap.empty in + class_type t abstracts + +let this_class_type t abstracts = let reason = replace_reason (fun desc -> RStatics desc) (reason_of_t t) in - ThisClassT (reason, t) + ThisClassT (reason, t, abstracts) + +let nonabstract_this_class_type t = + let abstracts = abstracts_type t SMap.empty SMap.empty in + this_class_type t abstracts let extends_type r l u = let reason = replace_reason (fun desc -> RExtends desc) r in diff --git a/src/typing/type_annotation.ml b/src/typing/type_annotation.ml index 60c272b1e40..21b561e0785 100644 --- a/src/typing/type_annotation.ml +++ b/src/typing/type_annotation.ml @@ -419,8 +419,12 @@ let rec convert cx tparams_map = Ast.Type.(function | "Class" -> check_type_param_arity cx loc typeParameters 1 (fun () -> let t = convert_type_params () |> List.hd in + let abstracts = + let reason = mk_reason (RAbstractsOf (desc_of_t t)) loc in + AbstractsT (reason, (SMap.empty, SMap.empty)) + in let reason = mk_reason (RStatics (desc_of_t t)) loc in - DefT (reason, ClassT t) + DefT (reason, ClassT (t, abstracts)) ) | "Function" | "function" -> @@ -611,9 +615,13 @@ let rec convert cx tparams_map = Ast.Type.(function | loc, Function { Function. params = (_, { Function.Params.params; rest }); + async; + generator; returnType; typeParameters; } -> + assert(not async); + assert(not generator); let tparams, tparams_map = mk_type_param_declarations cx ~tparams_map typeParameters in @@ -671,24 +679,25 @@ let rec convert cx tparams_map = Ast.Type.(function let props_map = match List.rev call_props with | [] -> props_map | [t] -> - let p = Field (None, t, Positive) in + let p = Field ((Property.Explicit (loc_of_t t), None, t), Positive) in SMap.add "$call" p props_map | t0::t1::ts -> let callable_reason = mk_reason (RCustom "callable object type") loc in let rep = InterRep.make t0 t1 ts in let t = DefT (callable_reason, IntersectionT rep) in - let p = Field (None, t, Positive) in + let p = Field ((Property.Explicit (loc_of_t t0), None, t), Positive) in SMap.add "$call" p props_map in (* Use the same reason for proto and the ObjT so we can walk the proto chain and use the root proto reason to build an error. *) let props_map, proto = match proto with - | Some t -> + | Some (loc, t) -> (* The existence of a callable property already implies that * __proto__ = Function.prototype. Treat __proto__ as a property *) if callable then - SMap.add "__proto__" (Field (None, t, Neutral)) props_map, + let kind = Property.Explicit loc in + SMap.add "__proto__" (Field ((kind, None, t), Neutral)) props_map, FunProtoT (locationless_reason RFunctionPrototype) else props_map, t @@ -711,12 +720,15 @@ let rec convert cx tparams_map = Ast.Type.(function match prop with | { Object.Property. key; value = Object.Property.Init value; optional; variance; _method; - static = _; (* object types don't have static props *) + abstract; + static; } -> + assert(not abstract); + assert(not static); begin match key with | Ast.Expression.Object.Property.Literal - (loc, { Ast.Literal.value = Ast.Literal.String name; _ }) - | Ast.Expression.Object.Property.Identifier (loc, name) -> + (key_loc, { Ast.Literal.value = Ast.Literal.String name; _ }) + | Ast.Expression.Object.Property.Identifier (key_loc, name) -> let t = convert cx tparams_map value in if name = "__proto__" && not (_method || optional) && variance = None then @@ -724,12 +736,13 @@ let rec convert cx tparams_map = Ast.Type.(function let proto = Tvar.mk_where cx reason (fun tout -> Flow.flow cx (t, ObjTestProtoT (reason, tout)) ) in - props, Some (Flow.mk_typeof_annotation cx reason proto) + props, Some (loc, Flow.mk_typeof_annotation cx reason proto) else + let kind = Property.Explicit loc in let t = if optional then Type.optional t else t in let polarity = if _method then Positive else polarity variance in - let props = SMap.add name (Field (Some loc, t, polarity)) props in - props, proto + let field = Field ((kind, Some key_loc, t), polarity) in + SMap.add name field props, proto | _ -> Flow.add_output cx (FlowError.EUnsupportedKeyInObjectType loc); props, proto @@ -738,25 +751,24 @@ let rec convert cx tparams_map = Ast.Type.(function (* unsafe getter property *) | { Object.Property. key = Ast.Expression.Object.Property.Identifier (id_loc, name); - value = Object.Property.Get (loc, f); + value = Object.Property.Get (get_loc, f); _ } -> - Flow_js.add_output cx (FlowError.EUnsafeGettersSetters loc); - let function_type = convert cx tparams_map (loc, Ast.Type.Function f) in - let return_t = Type.extract_getter_type function_type in - let props = Properties.add_getter name (Some id_loc) return_t props in - props, proto + Flow_js.add_output cx (FlowError.EUnsafeGettersSetters get_loc); + let fn_type = convert cx tparams_map (get_loc, Ast.Type.Function f) in + let return_t = Type.extract_getter_type fn_type in + let get = (Property.Explicit loc, Some id_loc, return_t) in + Properties.add_getter name get props, proto (* unsafe setter property *) | { Object.Property. key = Ast.Expression.Object.Property.Identifier (id_loc, name); - value = Object.Property.Set (loc, f); + value = Object.Property.Set (set_loc, f); _ } -> Flow_js.add_output cx (FlowError.EUnsafeGettersSetters loc); - let function_type = convert cx tparams_map (loc, Ast.Type.Function f) in - let param_t = Type.extract_setter_type function_type in - let props = Properties.add_setter name (Some id_loc) param_t props in - props, proto - + let fn_type = convert cx tparams_map (set_loc, Ast.Type.Function f) in + let param_t = Type.extract_setter_type fn_type in + let set = (Property.Explicit loc, Some id_loc, param_t) in + Properties.add_setter name set props, proto | { Object.Property. value = Object.Property.Get _ | Object.Property.Set _; @@ -770,17 +782,18 @@ let rec convert cx tparams_map = Ast.Type.(function | None -> Some ([c], None, SMap.empty, None) | Some (cs, d, pmap, proto) -> Some (c::cs, d, pmap, proto) in - let make_dict { Object.Indexer.id; key; value; variance; _ } = + let make_dict loc { Object.Indexer.id; key; value; variance; _ } = Some { Type. dict_name = Option.map id snd; + dict_kind = Property.Explicit loc; key = convert cx tparams_map key; value = convert cx tparams_map value; dict_polarity = polarity variance; } in let add_dict loc indexer = function - | None -> Some ([], make_dict indexer, SMap.empty, None) - | Some (cs, None, pmap, proto) -> Some (cs, make_dict indexer, pmap, proto) + | None -> Some ([], make_dict loc indexer, SMap.empty, None) + | Some (cs, None, pmap, proto) -> Some (cs, make_dict loc indexer, pmap, proto) | Some (_, Some _, _, _) as o -> Flow.add_output cx FlowError.(EUnsupportedSyntax (loc, MultipleIndexers)); diff --git a/src/typing/type_filter.ml b/src/typing/type_filter.ml index 753d2bce0b5..19296c37bfb 100644 --- a/src/typing/type_filter.ml +++ b/src/typing/type_filter.ml @@ -283,6 +283,7 @@ let object_ cx t = key = StrT.why r; value = DefT (replace_reason_const MixedT.desc r, MixedT Mixed_everything); dict_name = None; + dict_kind = Property.Explicit (loc_of_reason r); dict_polarity = Neutral; } in let proto = ObjProtoT reason in diff --git a/src/typing/type_mapper.ml b/src/typing/type_mapper.ml index daed0b44412..af37355145e 100644 --- a/src/typing/type_mapper.ml +++ b/src/typing/type_mapper.ml @@ -41,16 +41,18 @@ class ['a] t = object(self) if t'' == t' then t else BoundT t'' | ExistsT _ -> t - | ThisClassT (r, t') -> + | ThisClassT (r, t', abstracts) -> let t'' = self#type_ cx map_cx t' in - if t'' == t' then t - else ThisClassT (r, t'') + let abstracts' = self#type_ cx map_cx abstracts in + if t'' == t' && abstracts' == abstracts then t + else ThisClassT (r, t'', abstracts') | ThisTypeAppT (r, t1, t2, tlist_opt) -> let t1' = self#type_ cx map_cx t1 in let t2' = self#type_ cx map_cx t2 in let tlist_opt' = OptionUtils.ident_map (ListUtils.ident_map (self#type_ cx map_cx)) tlist_opt in if t1' == t1 && t2' == t2 && tlist_opt' == tlist_opt then t else ThisTypeAppT(r, t1', t2', tlist_opt') + | AbstractsT _ -> t | ExactT (r, t') -> let t'' = self#type_ cx map_cx t' in if t'' == t' then t @@ -162,10 +164,11 @@ class ['a] t = object(self) if arrtype == arrtype' then t else ArrT arrtype' | CharSetT _ -> t - | ClassT t' -> + | ClassT (t', abstracts) -> let t'' = self#type_ cx map_cx t' in - if t'' == t' then t - else ClassT t'' + let abstracts' = self#type_ cx map_cx abstracts in + if t'' == t' && abstracts' == abstracts then t + else ClassT (t'', abstracts') | InstanceT (st, su, impl, instt) -> let st' = self#type_ cx map_cx st in let su' = self#type_ cx map_cx su in @@ -401,14 +404,15 @@ class ['a] t = object(self) else { flags; dict_t = dict_t'; props_tmap = props_tmap'; proto_t = proto_t' } - method dict_type cx map_cx ({dict_name; key; value; dict_polarity} as t) = + method dict_type cx map_cx t = + let {dict_name; dict_kind; key; value; dict_polarity} = t in let key' = self#type_ cx map_cx key in let value' = self#type_ cx map_cx value in if key' == key && value' == value then t else let key = key' in let value = value' in - {dict_name; key; value; dict_polarity} + {dict_name; dict_kind; key; value; dict_polarity} method arr_type cx map_cx t = match t with @@ -506,6 +510,7 @@ class ['a] t = object(self) let t'' = self#type_ cx map_cx t' in if t'' == t' then t else GetStaticsT (r, t'') + | AssertNonabstractT _ -> t | GetProtoT (r, t') -> let t'' = self#type_ cx map_cx t' in if t'' == t' then t @@ -539,14 +544,18 @@ class ['a] t = object(self) let t'' = self#type_ cx map_cx t' in if t'' == t' then t else ImplementsT (use_op, t'') - | MixinT (r, t') -> + | MixinT (use_op, r, t') -> let t'' = self#type_ cx map_cx t' in if t'' == t' then t - else MixinT (r, t'') + else MixinT (use_op, r, t'') | ToStringT (r, t') -> let t'' = self#type_ cx map_cx t' in if t'' == t' then t else ToStringT (r, t'') + | AccAbstractsT (r, masks, local_abstracts, t') -> + let t'' = self#type_ cx map_cx t' in + if t'' == t' then t + else AccAbstractsT (r, masks, local_abstracts, t'') | AdderT (r, flip, t1, t2) -> let t1' = self#type_ cx map_cx t1 in let t2' = self#type_ cx map_cx t2 in @@ -1036,7 +1045,7 @@ class ['a] t = object(self) if r' == r then t else Resolve r' | Super ((reason, props, dict, flags), r) -> - let props' = SMap.ident_map (fun (t, b) -> (self#type_ cx map_cx t, b)) props in + let props' = SMap.ident_map (fun (k, t, b) -> (k, self#type_ cx map_cx t, b)) props in let dict' = OptionUtils.ident_map (self#dict_type cx map_cx) dict in let r' = self#resolve cx map_cx r in if r' == r && props' == props then t @@ -1205,10 +1214,10 @@ class ['a] t = object(self) if tlist' == tlist && resolvednelist' == resolvednelist then t else List (tlist', resolvednelist', join) - method resolved_prop cx map_cx ((t, own) as prop) = + method resolved_prop cx map_cx ((k, t, own) as prop) = let t' = self#type_ cx map_cx t in if t' == t then prop - else (t', own) + else (k, t', own) method resolved cx map_cx t = let t' = Nel.ident_map (fun ((r, props, dict, flags) as slice) -> @@ -1313,11 +1322,11 @@ class ['a] t = object(self) let obj' = self#resolved_object cx map_cx obj in if dict' == dict && props' == props && obj' == obj then t else ResolveDict (dict', props', obj') - | ResolveProp (s, props, obj) -> + | ResolveProp (s, loc, key_loc, props, obj) -> let props' = SMap.ident_map (Property.ident_map_t (self#type_ cx map_cx)) props in let obj' = self#resolved_object cx map_cx obj in if props' == props && obj' == obj then t - else ResolveProp (s, props', obj') + else ResolveProp (s, loc, key_loc, props', obj') method stack_tail cx map_cx tail = ListUtils.ident_map (self#stack_tail_elem cx map_cx) tail diff --git a/src/typing/type_normalizer.ml b/src/typing/type_normalizer.ml index d22ec9a766b..c24fb5fe62d 100644 --- a/src/typing/type_normalizer.ml +++ b/src/typing/type_normalizer.ml @@ -165,7 +165,7 @@ let rec normalize_type_impl cx ids t = match t with | CustomFunT (_, Mixin) -> let obj = DefT (locationless_reason RObjectType, AnyObjT) in let arr = DefT (locationless_reason RArray, ArrT (ArrayAT(obj, None))) in - let tout = class_type obj in + let tout = nonabstract_class_type obj in let tins = [] in let rest_param = Some ("objects", arr) in let params_names = [] in @@ -255,7 +255,7 @@ let rec normalize_type_impl cx ids t = match t with | CustomFunT (_, ReactCreateClass) -> let component_class = let instance = fake_instance "ReactClass" in - typeapp (class_type instance) [Locationless.AnyT.t] + typeapp (nonabstract_class_type instance) [Locationless.AnyT.t] in fake_fun ([Some "spec"]) [Locationless.AnyT.t] None component_class @@ -285,13 +285,13 @@ let rec normalize_type_impl cx ids t = match t with let any = DefT (locationless_reason RAny, AnyT) in let react_element = let id = Context.make_nominal cx in - let instance = fake_instance "React$Element" in - typeapp (poly_type id [config_tp] (class_type instance)) [config] + let cls = nonabstract_class_type (fake_instance "React$Element") in + typeapp (poly_type id [config_tp] cls) [config] in let component_class = let id = Context.make_nominal cx in - let instance = fake_instance "ReactClass" in - typeapp (poly_type id [config_tp] (class_type instance)) [config] + let cls = nonabstract_class_type (fake_instance "ReactClass") in + typeapp (poly_type id [config_tp] cls) [config] in let stateless_functional_component = let params_names = [Some "config"; Some "context"] in @@ -380,13 +380,20 @@ let rec normalize_type_impl cx ids t = match t with let reason = locationless_reason (desc_of_reason reason) in DefT (reason, PolyT (xs, normalize_type_impl cx ids t, id)) - | DefT (reason, ClassT t) -> + | DefT (reason, ClassT (t, abstracts)) -> let reason = locationless_reason (desc_of_reason reason) in - DefT (reason, ClassT (normalize_type_impl cx ids t)) + let normalize = normalize_type_impl cx ids in + DefT (reason, ClassT (normalize t, normalize abstracts)) - | ThisClassT (reason, t) -> + | ThisClassT (reason, t, abstracts) -> let reason = locationless_reason (desc_of_reason reason) in - ThisClassT (reason, normalize_type_impl cx ids t) + let normalize = normalize_type_impl cx ids in + ThisClassT (reason, normalize t, normalize abstracts) + + | AbstractsT (reason, (static_abstracts, abstracts)) -> + let normalize reason = locationless_reason (desc_of_reason reason) in + let map = SMap.map normalize in + AbstractsT (normalize reason, (map static_abstracts, map abstracts)) | DefT (reason, TypeT t) -> let reason = locationless_reason (desc_of_reason reason) in @@ -594,6 +601,5 @@ and collect_intersection_members ts = TypeSet.add x acc ) TypeSet.empty ts - let normalize_type cx t = normalize_type_impl cx ISet.empty t diff --git a/src/typing/type_printer.ml b/src/typing/type_printer.ml index e7946be5c98..356f17a45e0 100644 --- a/src/typing/type_printer.ml +++ b/src/typing/type_printer.ml @@ -55,18 +55,21 @@ let rec type_printer_impl ~size override enclosure cx t = let pp_opt = type_printer_opt ~size override in let rec prop x = function - | Field (_, t, polarity) -> spf "%s%s: %s" + | Field ((_, _, t), polarity) -> spf "%s%s: %s" (Polarity.sigil polarity) (prop_name cx x t) (pp EnclosureProp cx t) - | Get (_, t) -> spf "get %s(): %s" x (pp EnclosureRet cx t) - | Set (_, t) -> spf "set %s(value: %s): void" x (pp EnclosureParam cx t) - | GetSet (loc1, t1, loc2, t2) -> + | Get (_, _, t) -> spf "get %s(): %s" x (pp EnclosureRet cx t) + | Set (_, _, t) -> spf "set %s(value: %s): void" x (pp EnclosureParam cx t) + | GetSet (get, set) -> String.concat ", " [ - prop x (Get (loc1, t1)); - prop x (Set (loc2, t2)); + prop x (Get get); + prop x (Set set); ] - | Method (_, t) -> spf "%s%s" + | Method (_, _, t) -> spf "%s%s" + (prop_name cx x t) + (pp EnclosureMethod cx t) + | Abstract (_, _, t) -> spf "abstract %s%s" (prop_name cx x t) (pp EnclosureMethod cx t) in @@ -82,7 +85,7 @@ let rec type_printer_impl ~size override enclosure cx t = in let indexer = (match dict_t with - | Some { dict_name; key; value; dict_polarity } -> + | Some { dict_name; dict_kind = _; key; value; dict_polarity } -> let indexer_prefix = if props <> "" then ", " @@ -209,8 +212,8 @@ let rec type_printer_impl ~size override enclosure cx t = |> String.concat ", " in let type_s = match t with - | DefT (_, ClassT u) - | ThisClassT (_, u) -> + | DefT (_, ClassT (u, _)) + | ThisClassT (_, u, _) -> spf "%s<%s>" (pp EnclosureNone cx u) xs_str | _ -> spf "<%s>%s" xs_str (pp @@ -257,7 +260,7 @@ let rec type_printer_impl ~size override enclosure cx t = | ShapeT t -> Some (spf "$Shape<%s>" (pp EnclosureNone cx t)) (* The following types are not syntax-supported *) - | DefT (_, ClassT t) -> + | DefT (_, ClassT (t, _)) -> Some (spf "[class: %s]" (pp EnclosureNone cx t)) | DefT (_, TypeT t) -> @@ -301,6 +304,7 @@ let rec type_printer_impl ~size override enclosure cx t = (* TODO: Fix these *) + | AbstractsT _ | FunProtoT _ | FunProtoBindT _ | CustomFunT _ @@ -323,8 +327,8 @@ let rec type_printer_impl ~size override enclosure cx t = and instance_of_poly_type_printer ~size override enclosure cx = function - | DefT (_, PolyT (_, ThisClassT (_, t), _)) - | DefT (_, PolyT (_, DefT (_, ClassT t), _)) + | DefT (_, PolyT (_, ThisClassT (_, t, _), _)) + | DefT (_, PolyT (_, DefT (_, ClassT (t, _)), _)) -> type_printer ~size override enclosure cx t | DefT (_, PolyT (_, DefT (reason, TypeT _), _)) @@ -456,8 +460,8 @@ let rec is_printed_type_parsable_impl weak cx enclosure = function (* unwrap PolyT (ClassT t) because class names are parsable as part of a polymorphic type declaration. *) let t = match t with - | ThisClassT (_, u) - | DefT (_, ClassT u) -> u + | ThisClassT (_, u, _) + | DefT (_, ClassT (u, _)) -> u | _ -> t in is_printed_type_parsable_impl weak cx EnclosureNone t @@ -478,10 +482,10 @@ let rec is_printed_type_parsable_impl weak cx enclosure = function (* these are types which are not really parsable, but they make sense to a human user in cases of autocompletion *) | DefT (_, TypeT t) - | DefT (_, ClassT t) + | DefT (_, ClassT (t, _)) | AnyWithUpperBoundT t | AnyWithLowerBoundT t - | ThisClassT (_, t) + | ThisClassT (_, t, _) when weak -> is_printed_type_parsable_impl weak cx EnclosureNone t @@ -494,9 +498,9 @@ let rec is_printed_type_parsable_impl weak cx enclosure = function false and is_instantiable_poly_type weak cx enclosure = function - | DefT (_, PolyT (_, ThisClassT (_, t), _)) - | DefT (_, PolyT (_, DefT (_, ClassT t), _)) - -> is_printed_type_parsable_impl weak cx enclosure t + | DefT (_, PolyT (_, ThisClassT (_, t, _), _)) + | DefT (_, PolyT (_, DefT (_, ClassT (t, _)), _)) -> + is_printed_type_parsable_impl weak cx enclosure t | DefT (_, PolyT (_, DefT (_, TypeT _), _)) -> true diff --git a/src/typing/type_visitor.ml b/src/typing/type_visitor.ml index dc5a095cfec..45875cb4319 100644 --- a/src/typing/type_visitor.ml +++ b/src/typing/type_visitor.ml @@ -101,7 +101,10 @@ class ['a] t = object(self) let acc = self#list (self#predicate cx) acc (Key_map.values n_map) in acc - | ThisClassT (_, t) -> self#type_ cx pole acc t + | ThisClassT (_, t, abstracts) -> + let acc = self#type_ cx pole acc t in + let acc = self#type_ cx pole acc abstracts in + acc | ThisTypeAppT (_, t, this, ts_opt) -> let acc = self#type_ cx pole acc t in @@ -109,6 +112,8 @@ class ['a] t = object(self) let acc = self#opt (self#list (self#type_ cx pole_TODO)) acc ts_opt in acc + | AbstractsT _ -> acc + | ReposT (_, t) | InternalT (ReposUpperT (_, t)) -> self#type_ cx pole acc t @@ -138,7 +143,10 @@ class ['a] t = object(self) | CharSetT _ -> acc - | ClassT t -> self#type_ cx pole acc t + | ClassT (t, abstracts) -> + let acc = self#type_ cx pole acc t in + let acc = self#type_ cx pole acc abstracts in + acc | InstanceT (static, super, implements, insttype) -> let acc = self#type_ cx pole acc static in @@ -302,7 +310,11 @@ class ['a] t = object(self) let acc = self#fun_call_type cx acc fn in acc - | GetStaticsT (_, t) + | GetStaticsT (_, t) -> + self#type_ cx pole_TODO acc t + + | AssertNonabstractT _ -> acc + | GetProtoT (_, t) | SetProtoT (_, t) -> self#type_ cx pole_TODO acc t @@ -318,8 +330,9 @@ class ['a] t = object(self) | SuperT (_, _, DerivedInstance i) -> self#inst_type cx pole_TODO acc i | SuperT (_, _, DerivedStatics o) -> self#obj_type cx pole_TODO acc o | ImplementsT (_, t) -> self#type_ cx pole_TODO acc t - | MixinT (_, t) -> self#type_ cx pole_TODO acc t + | MixinT (_, _, t) -> self#type_ cx pole_TODO acc t | ToStringT (_, t) -> self#type_ cx pole_TODO acc t + | AccAbstractsT (_, _, _, t) -> self#type_ cx pole_TODO acc t | AdderT (_, _, a, b) -> let acc = self#type_ cx pole_TODO acc a in @@ -623,6 +636,7 @@ class ['a] t = object(self) method dict_type cx pole acc d = let { dict_name = _; + dict_kind = _; key; value; dict_polarity = p; @@ -636,11 +650,12 @@ class ['a] t = object(self) |> self#smap (self#prop cx pole) acc method private prop cx pole acc = function - | Field (_, t, p) -> self#type_ cx (P.mult (pole, p)) acc t - | Method (_, t) -> self#type_ cx pole acc t - | Get (_, t) -> self#type_ cx pole acc t - | Set (_, t) -> self#type_ cx (P.inv pole) acc t - | GetSet (_, t1, _, t2) -> + | Field ((_, _, t), p) -> self#type_ cx (P.mult (pole, p)) acc t + | Method (_, _, t) -> self#type_ cx pole acc t + | Abstract (_, _, t) -> self#type_ cx pole acc t + | Get (_, _, t) -> self#type_ cx pole acc t + | Set (_, _, t) -> self#type_ cx (P.inv pole) acc t + | GetSet ((_, _, t1), (_, _, t2)) -> let acc = self#type_ cx pole acc t1 in let acc = self#type_ cx (P.inv pole) acc t2 in acc @@ -855,7 +870,7 @@ class ['a] t = object(self) acc method private object_kit_slice cx acc (_, props, dict, _) = - let acc = self#smap (fun acc (t, _) -> self#type_ cx pole_TODO acc t) acc props in + let acc = self#smap (fun acc (_, t, _) -> self#type_ cx pole_TODO acc t) acc props in let acc = self#opt (self#dict_type cx pole_TODO) acc dict in acc @@ -873,7 +888,7 @@ class ['a] t = object(self) let acc = self#smap (self#prop cx pole_TODO) acc props in let acc = self#react_resolved_object cx acc o in acc - | ResolveProp (_, props, o) -> + | ResolveProp (_, _, _, props, o) -> let acc = self#smap (self#prop cx pole_TODO) acc props in let acc = self#react_resolved_object cx acc o in acc diff --git a/tests/class_abstracts/.flowconfig b/tests/class_abstracts/.flowconfig new file mode 100644 index 00000000000..97cbec220a4 --- /dev/null +++ b/tests/class_abstracts/.flowconfig @@ -0,0 +1,2 @@ +[options] + no_flowlib=false diff --git a/tests/class_abstracts/A.js b/tests/class_abstracts/A.js new file mode 100644 index 00000000000..87ebd7a671c --- /dev/null +++ b/tests/class_abstracts/A.js @@ -0,0 +1,4 @@ +export class A { + abstract m(n: number): number; + abstract static static_m(s: string): string; +} diff --git a/tests/class_abstracts/async.js b/tests/class_abstracts/async.js new file mode 100644 index 00000000000..6f9746a01b2 --- /dev/null +++ b/tests/class_abstracts/async.js @@ -0,0 +1,27 @@ +class A { + abstract async nonstatic(): Promise; + abstract static async static(): Promise; +} +let a = new A; //ng + +class B extends A { + nonstatic(): Promise { return new Promise(resolve => resolve(5)); } + static static() { return new Promise(resolve => resolve("a string")); } +} +let b = new B; + +class C extends A { + async nonstatic() { + return "another string"; //ng, non-number + } + static async static() { + return 13; //ng, non-string + } +} +let c = new C; + +class D extends A { + async nonstatic() { return 7; } + static async static() { return "yet another string"; } +} +let d = new D; diff --git a/tests/class_abstracts/class_abstracts.exp b/tests/class_abstracts/class_abstracts.exp new file mode 100644 index 00000000000..46037b13797 --- /dev/null +++ b/tests/class_abstracts/class_abstracts.exp @@ -0,0 +1,362 @@ +Error: async.js:5 + 5: let a = new A; //ng + ^^^^^ new `A`. Unimplemented abstract(s) found in + 5: let a = new A; //ng + ^ abstracts of `A` + Abstract(s): + 2: abstract async nonstatic(): Promise; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method + 3: abstract static async static(): Promise; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: async.js:13 + 13: class C extends A { + ^ C. Cannot extend + 13: class C extends A { + ^ A + Property `nonstatic` is incompatible: + v------------------ + 14: async nonstatic() { + 15: return "another string"; //ng, non-number + 16: } + ^ async function. This type is incompatible with + 2: abstract async nonstatic(): Promise; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method + The return is incompatible: + 15: return "another string"; //ng, non-number + ^^^^^^^^^^^^^^^^^^^^^^^^ async return. Has some incompatible type argument with + 2: abstract async nonstatic(): Promise; + ^^^^^^^^^^^^^^^ Promise + Type argument `R` is incompatible: + 15: return "another string"; //ng, non-number + ^^^^^^^^^^^^^^^^ string. This type is incompatible with + 2: abstract async nonstatic(): Promise; + ^^^^^^ number + +Error: async.js:13 + 13: class C extends A { + ^ C. Cannot extend + 13: class C extends A { + ^ A + Property `static` is incompatible: + v---------------------- + 17: static async static() { + 18: return 13; //ng, non-string + 19: } + ^ async function. This type is incompatible with + 3: abstract static async static(): Promise; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method + The return is incompatible: + 18: return 13; //ng, non-string + ^^^^^^^^^^ async return. Has some incompatible type argument with + 3: abstract static async static(): Promise; + ^^^^^^^^^^^^^^^ Promise + Type argument `R` is incompatible: + 18: return 13; //ng, non-string + ^^ number. This type is incompatible with + 3: abstract static async static(): Promise; + ^^^^^^ string + +Error: declare.js:8 + 8: let a = new A; //ng + ^^^^^ new `A`. Unimplemented abstract(s) found in + 8: let a = new A; //ng + ^ abstracts of `A` + Abstract(s): + 2: abstract static create(): this; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method + 3: abstract static s(): string; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method + 4: abstract clone(): this; + ^^^^^^^^^^^^^^^^^^^^^^ abstract method + 5: abstract n(): number; + ^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: declare.js:14 + 14: let partial = new Partial; //ng + ^^^^^^^^^^^ new `Partial`. Unimplemented abstract(s) found in + 14: let partial = new Partial; //ng + ^^^^^^^ abstracts of `Partial` + Abstract(s): + 3: abstract static s(): string; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method + 5: abstract n(): number; + ^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: extends.js:16 + 16: let B5: Class = A; //ng + ^^^^^^^^ abstracts of `A`. Unimplemented abstract(s) found in + 16: let B5: Class = A; //ng + ^ abstracts of `A` + Abstract(s): + 2: abstract m(n: number): number; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. See: A.js:2 + 3: abstract static static_m(s: string): string; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. See: A.js:3 + +Error: implement.js:29 + 29: set x(k: string): void {} //ng + ^^^^^^^^^^^^^^^^^^^^^^^^^ setter. A setter without a getter cannot implement + 24: abstract x(k: string): void; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: implement.js:30 + 30: static set y(k: string): void {} //ng + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ setter. A setter without a getter cannot implement + 25: abstract static y(k: string): void; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: implement.js:66 + 66: let amc = new AbstractMethodConcrete; //ng + ^^^^^^^^^^^^^^^^^^^^^^^^^^ new `AbstractMethodConcrete`. Unimplemented abstract(s) found in + 66: let amc = new AbstractMethodConcrete; //ng + ^^^^^^^^^^^^^^^^^^^^^^ abstracts of `AbstractMethodConcrete` + Abstract(s): + 63: abstract x(): string; + ^^^^^^^^^^^^^^^^^^^^^ abstract method + 64: abstract static y(): string; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: import.js:3 + 3: let a1: A = new A; //ng + ^^^^^ new `A`. Unimplemented abstract(s) found in + 3: let a1: A = new A; //ng + ^ abstracts of `A` + Abstract(s): + 2: abstract m(n: number): number; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. See: A.js:2 + 3: abstract static static_m(s: string): string; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. See: A.js:3 + +Error: import.js:4 + 4: let A2: Class = A; //ng + ^^^^^^^^ abstracts of `A`. Unimplemented abstract(s) found in + 4: let A2: Class = A; //ng + ^ abstracts of `A` + Abstract(s): + 2: abstract m(n: number): number; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. See: A.js:2 + 3: abstract static static_m(s: string): string; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. See: A.js:3 + +Error: import.js:6 + 6: let s1: string = A.static_m("qwerty"); //ng + ^^^^^^^^^^^^^^^^^^^^ call of method `static_m`. Unimplemented abstract(s) found in + 6: let s1: string = A.static_m("qwerty"); //ng + ^ abstracts of `A` + Abstract(s): + 2: abstract m(n: number): number; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. See: A.js:2 + 3: abstract static static_m(s: string): string; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. See: A.js:3 + +Error: mask.js:7 + 7: abstract x(): string; //ng + ^^^^^^^^^^^^^^^^^^^^^ abstract method. Cannot mask non-abstract + 2: x: () => string; + ^^^^^^^^^^^^^^^^ field + +Error: mask.js:8 + 8: abstract static y(): string; //ng + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. Cannot mask non-abstract + 3: static y: () => string; + ^^^^^^^^^^^^^^^^^^^^^^^ field + +Error: mask.js:17 + 17: abstract x(): string; //ng + ^^^^^^^^^^^^^^^^^^^^^ abstract method. Cannot mask non-abstract + 12: get x(): () => string { return () => "x"; } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ getter + +Error: mask.js:18 + 18: abstract static y(): string; //ng + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. Cannot mask non-abstract + 13: static get y(): () => string { return () => "static y"; } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ getter + +Error: mask.js:27 + 27: abstract x(k: string): void; //ng + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. Cannot mask non-abstract + 22: set x(k: string): void {} + ^^^^^^^^^^^^^^^^^^^^^^^^^ setter + +Error: mask.js:28 + 28: abstract static y(k: string): void; //ng + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. Cannot mask non-abstract + 23: static set y(k: string): void {} + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ setter + +Error: mask.js:39 + 39: abstract x(): string; //ng + ^^^^^^^^^^^^^^^^^^^^^ abstract method. Cannot mask non-abstract + 32: get x(): () => string { return () => "x"; } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ getter + +Error: mask.js:39 + 39: abstract x(): string; //ng + ^^^^^^^^^^^^^^^^^^^^^ abstract method. Cannot mask non-abstract + 33: set x(k: string): void {} + ^^^^^^^^^^^^^^^^^^^^^^^^^ setter + +Error: mask.js:40 + 40: abstract static y(): string; //ng + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. Cannot mask non-abstract + 34: static get y(): () => string { return () => "static y"; } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ getter + +Error: mask.js:40 + 40: abstract static y(): string; //ng + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. Cannot mask non-abstract + 35: static set y(k: string): void {} + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ setter + +Error: mask.js:49 + 49: abstract x(): string; //ng + ^^^^^^^^^^^^^^^^^^^^^ abstract method. Cannot mask non-abstract + 44: x(): string { return "x"; } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ method + +Error: mask.js:50 + 50: abstract static y(): string; //ng + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method. Cannot mask non-abstract + 45: static y(): string { return "static y"; } + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method + +Error: method_body.js:14 + 14: super.n = () => 5; //ng + ^^^^^^^ statics of `A`. Covariant property `n` incompatible with contravariant use in + 14: super.n = () => 5; //ng + ^^^^^^^ assignment of property `n` + +Error: method_body.js:15 + 15: let k = super.create; //ng + ^^^^^^ property `create`. Unimplemented abstract static `create` found in + 12: class AbstractSupers extends A { + ^ abstracts of `A` + +Error: method_body.js:16 + 16: return super.create(); //ng + ^^^^^^^^^^^^^^ call of method `create`. Unimplemented abstract static `create` found in + 12: class AbstractSupers extends A { + ^ abstracts of `A` + +Error: method_body.js:19 + 19: super.s = () => "a string"; //ng + ^ property `s`. Covariant property `s` incompatible with contravariant use in + 19: super.s = () => "a string"; //ng + ^^^^^^^ assignment of property `s` + +Error: method_body.js:20 + 20: let k = super.clone; //ng + ^^^^^ property `clone`. Unimplemented abstract `clone` found in + 20: let k = super.clone; //ng + ^^^^^ abstracts of `A` + +Error: method_body.js:21 + 21: return super.clone(); //ng + ^^^^^^^^^^^^^ call of method `clone`. Unimplemented abstract `clone` found in + 21: return super.clone(); //ng + ^^^^^ abstracts of `A` + +Error: mixin.js:12 + 12: declare class K2 extends Concrete1 mixins Abstract2 {} //ng + ^^ K2. Unimplemented abstract(s) found in + 12: declare class K2 extends Concrete1 mixins Abstract2 {} //ng + ^^^^^^^^^ abstracts of `Abstract2` + Abstract(s): + 7: abstract n(): number; + ^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: mixin.js:13 + 13: declare class K3 extends Abstract1 mixins Concrete2 {} //ng + ^^ K3. Unimplemented abstract(s) found in + 13: declare class K3 extends Abstract1 mixins Concrete2 {} //ng + ^^^^^^^^^ abstracts of `Abstract1` + Abstract(s): + 4: abstract m(): number; + ^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: mixin.js:14 + 14: declare class K4 extends Abstract1 mixins Abstract2 {} //ng + ^^ K4. Unimplemented abstract(s) found in + 14: declare class K4 extends Abstract1 mixins Abstract2 {} //ng + ^^^^^^^^^ abstracts of `Abstract1` + Abstract(s): + 4: abstract m(): number; + ^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: mixin.js:14 + 14: declare class K4 extends Abstract1 mixins Abstract2 {} //ng + ^^ K4. Unimplemented abstract(s) found in + 14: declare class K4 extends Abstract1 mixins Abstract2 {} //ng + ^^^^^^^^^ abstracts of `Abstract2` + Abstract(s): + 7: abstract n(): number; + ^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: mixin.js:18 + 18: declare class K5 mixins AbstractIsect {} //ng + ^^^^^^^^^^^^^ AbstractIsect. Illegal mixin + 17: declare var AbstractIsect: T; + ^ T + +Error: mixin.js:27 + 27: let k2 = mix(Abstract1, Concrete2); //ng + ^^^^^^^^^ Abstract1 + 21: declare class K extends C1 mixins C2 {} + ^ K. Unimplemented abstract(s) found in + 21: declare class K extends C1 mixins C2 {} + ^^ abstracts of `Abstract1` + Abstract(s): + 4: abstract m(): number; + ^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: mixin.js:28 + 28: let k3 = mix(Concrete1, Abstract2); //ng + ^^^^^^^^^ Abstract2 + 21: declare class K extends C1 mixins C2 {} + ^ K. Unimplemented abstract(s) found in + 21: declare class K extends C1 mixins C2 {} + ^^ abstracts of `Abstract2` + Abstract(s): + 7: abstract n(): number; + ^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: mixin.js:32 + 32: class K extends mixin(Abstract1, Abstract2) {} + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ call of `mixin`. Unimplemented abstract(s) found in + 32: class K extends mixin(Abstract1, Abstract2) {} + ^^^^^^^^^ abstracts of `Abstract1` + Abstract(s): + 4: abstract m(): number; + ^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: mixin.js:32 + 32: class K extends mixin(Abstract1, Abstract2) {} + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ call of `mixin`. Unimplemented abstract(s) found in + 32: class K extends mixin(Abstract1, Abstract2) {} + ^^^^^^^^^ abstracts of `Abstract2` + Abstract(s): + 7: abstract n(): number; + ^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: static_property.js:12 + 12: return this.static_method(); + ^^^^^^^^^^^^^^^^^^^^ call of method `static_method`. Unimplemented abstract(s) found in + 12: return this.static_method(); + ^^^^ abstracts of `B` + Abstract(s): + 9: abstract static static_method(): string; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method + +Error: static_property.js:17 + 17: let s2: string = C.static_field(); //ng + ^^^^^^^^^^^^^^^^ call of method `static_field`. Unimplemented abstract(s) found in + 17: let s2: string = C.static_field(); //ng + ^ abstracts of `C` + Abstract(s): + 9: abstract static static_method(): string; + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ abstract method + + +Found 41 errors diff --git a/tests/class_abstracts/declare.js b/tests/class_abstracts/declare.js new file mode 100644 index 00000000000..a58280bc361 --- /dev/null +++ b/tests/class_abstracts/declare.js @@ -0,0 +1,22 @@ +declare class A { + abstract static create(): this; + abstract static s(): string; + abstract clone(): this; + abstract n(): number; + concreteClone(): this; +} +let a = new A; //ng + +declare class Partial extends A { + static create(): this; + clone(): this; +} +let partial = new Partial; //ng + +declare class B extends A { + static create(): this; + static s(): string; + clone(): this; + n(): number; +} +let b = new B; diff --git a/tests/class_abstracts/extends.js b/tests/class_abstracts/extends.js new file mode 100644 index 00000000000..62ea770c225 --- /dev/null +++ b/tests/class_abstracts/extends.js @@ -0,0 +1,22 @@ +import { A } from "./A.js" + +class B extends A { + m(n) { return n; } + static static_m(s) { return s; } +} + +class C extends (B: Class) { + n(): string { return "n"; } +} + +let b1 = new B; +let b2: A = new B; +let b3: B = new B; +let b4: C = new C; +let B5: Class = A; //ng +let B6: Class = B; +let B7: Class = B; + +let n1 = b1.m(1); +let s1 = B5.static_m("one"); +let s2 = B6.static_m("two"); diff --git a/tests/class_abstracts/implement.js b/tests/class_abstracts/implement.js new file mode 100644 index 00000000000..34e0ddb446a --- /dev/null +++ b/tests/class_abstracts/implement.js @@ -0,0 +1,66 @@ +class Field { + abstract x(): string; + abstract static y(): string; +} + +class FieldConcrete extends Field { + x: () => string; + static y: () => string; +} +let fc = new FieldConcrete; + +class Get { + abstract x(): string; + abstract static y(): string; +} + +class GetConcrete extends Get { + get x(): () => string { return () => "x"; } + static get y(): () => string { return () => "static y"; } +} +let gc = new GetConcrete; + +class Set { + abstract x(k: string): void; + abstract static y(k: string): void; +} + +class SetConcrete extends Set { + set x(k: string): void {} //ng + static set y(k: string): void {} //ng +} + +class GetSet { + abstract x(): string; + abstract static y(): string; +} + +class GetSetConcrete extends GetSet { + get x(): () => string { return () => "x"; } + set x(k: string): void {} + static get y(): () => string { return () => "static y"; } + static set y(k: string): void {} +} +let gsc = new GetSetConcrete; + +class Method { + abstract x(): string; + abstract static y(): string; +} + +class MethodConcrete extends Method { + x(): string { return "x"; } + static y(): string { return "static y"; } +} +let mc = new MethodConcrete; + +class AbstractMethod { + abstract x(): string; + abstract static y(): string; +} + +class AbstractMethodConcrete { + abstract x(): string; + abstract static y(): string; +} +let amc = new AbstractMethodConcrete; //ng diff --git a/tests/class_abstracts/import.js b/tests/class_abstracts/import.js new file mode 100644 index 00000000000..72f992cf15f --- /dev/null +++ b/tests/class_abstracts/import.js @@ -0,0 +1,6 @@ +import { A } from "./A.js" + +let a1: A = new A; //ng +let A2: Class = A; //ng + +let s1: string = A.static_m("qwerty"); //ng diff --git a/tests/class_abstracts/mask.js b/tests/class_abstracts/mask.js new file mode 100644 index 00000000000..6fee7d56609 --- /dev/null +++ b/tests/class_abstracts/mask.js @@ -0,0 +1,61 @@ +class Field { + x: () => string; + static y: () => string; +} + +class FieldMask extends Field { + abstract x(): string; //ng + abstract static y(): string; //ng +} + +class Get { + get x(): () => string { return () => "x"; } + static get y(): () => string { return () => "static y"; } +} + +class GetMask extends Get { + abstract x(): string; //ng + abstract static y(): string; //ng +} + +class Set { + set x(k: string): void {} + static set y(k: string): void {} +} + +class SetMask extends Set { + abstract x(k: string): void; //ng + abstract static y(k: string): void; //ng +} + +class GetSet { + get x(): () => string { return () => "x"; } + set x(k: string): void {} + static get y(): () => string { return () => "static y"; } + static set y(k: string): void {} +} + +class GetSetMask extends GetSet { + abstract x(): string; //ng + abstract static y(): string; //ng +} + +class Method { + x(): string { return "x"; } + static y(): string { return "static y"; } +} + +class MethodMask extends Method { + abstract x(): string; //ng + abstract static y(): string; //ng +} + +class AbstractMethod { + abstract x(): string; + abstract static y(): string; +} + +class AbstractMethodMask { + abstract x(): string; + abstract static y(): string; +} diff --git a/tests/class_abstracts/method_body.js b/tests/class_abstracts/method_body.js new file mode 100644 index 00000000000..ed90114334e --- /dev/null +++ b/tests/class_abstracts/method_body.js @@ -0,0 +1,58 @@ +class A { + abstract static create(): this; + abstract static n(): number; + abstract clone(): this; + abstract s(): string; + + concreteClone(): this { + return this.clone(); + } +} + +class AbstractSupers extends A { + static indirectCreate(): this { + super.n = () => 5; //ng + let k = super.create; //ng + return super.create(); //ng + } + indirectClone(): this { + super.s = () => "a string"; //ng + let k = super.clone; //ng + return super.clone(); //ng + } + indirectConcreteClone(): this { + return super.concreteClone(); + } +} + +class ImplA extends A { + static create(): this { + return new this; + } + clone(): this { + return this; + } +} + +class NonabstactSupers extends ImplA { + static indirectCreate(): this { + return super.create(); + } + indirectClone(): this { + return super.clone(); + } +} + +/* +// The extended class, ImplA, is typed as a non-abtract subtype of A, so `clone` and +// `create` are available on `super`. For `this` returns types, this use case +// is blocked by https://github.com/facebook/flow/issues/4240. +class C3 extends (ImplA: Class) { + static indirectCreate(): this { + return super.create(); //ok + } + indirectClone(): this { + return super.clone(); //ok + } +} +*/ diff --git a/tests/class_abstracts/mixin.js b/tests/class_abstracts/mixin.js new file mode 100644 index 00000000000..a29f12cd2f2 --- /dev/null +++ b/tests/class_abstracts/mixin.js @@ -0,0 +1,32 @@ +class Concrete1 {} +class Concrete2 {} +class Abstract1 { + abstract m(): number; +} +class Abstract2 { + abstract n(): number; +} + +// Abstracts do not mix in. +declare class K1 extends Concrete1 mixins Concrete2 {} +declare class K2 extends Concrete1 mixins Abstract2 {} //ng +declare class K3 extends Abstract1 mixins Concrete2 {} //ng +declare class K4 extends Abstract1 mixins Abstract2 {} //ng + +type T = typeof Abstract2 & typeof Abstract1; +declare var AbstractIsect: T; +declare class K5 mixins AbstractIsect {} //ng + +function mix(C1, C2) { + declare class K extends C1 mixins C2 {} + declare var k: K; + return k +} + +let k1 = mix(Concrete1, Concrete2); +let k2 = mix(Abstract1, Concrete2); //ng +let k3 = mix(Concrete1, Abstract2); //ng +let k4 = mix(Abstract1, Abstract2); //ng + +declare var mixin: $Facebookism$Mixin; +class K extends mixin(Abstract1, Abstract2) {} diff --git a/tests/class_abstracts/static_property.js b/tests/class_abstracts/static_property.js new file mode 100644 index 00000000000..5033fcfc805 --- /dev/null +++ b/tests/class_abstracts/static_property.js @@ -0,0 +1,17 @@ +class A { + static static_field: string; + abstract m(): void; +} +A.static_field = "a string"; + +class B { + static static_field: () => string; + abstract static static_method(): string; +} +B.static_field = function (): string { + return this.static_method(); +}; +let s1: string = B.static_field(); //ng + +class C extends B {} +let s2: string = C.static_field(); //ng