14 files changed

+169
-78
lines changed
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ end = struct
620620
run this#function_return_annotation return;
621621
run this#function_body_any body;
622622
run_opt this#predicate predicate;
623-
run_opt this#type_params tparams;
623+
run_opt (this#type_params ~kind:Flow_ast_mapper.FunctionTP) tparams;
624624
expr)
625625
loc
626626
expr
@@ -634,7 +634,7 @@ end = struct
634634
~is_polymorphic:(Option.is_some tparams)
635635
~kind:Var
636636
(fun _ _ ->
637-
run_opt this#type_params tparams;
637+
run_opt (this#type_params ~kind:Flow_ast_mapper.ComponentDeclarationTP) tparams;
638638
run this#component_params params;
639639
run this#component_body body;
640640
run this#component_renders_annotation renders;
@@ -905,7 +905,7 @@ end = struct
905905
run this#function_return_annotation return;
906906
run this#function_body_any body;
907907
run_opt this#predicate predicate;
908-
run_opt this#type_params tparams;
908+
run_opt (this#type_params ~kind:Flow_ast_mapper.FunctionTP) tparams;
909909
expr)
910910
loc
911911
expr
@@ -941,7 +941,7 @@ end = struct
941941
run this#function_return_annotation return;
942942
run this#function_body_any body;
943943
run_opt this#predicate predicate;
944-
run_opt this#type_params tparams;
944+
run_opt (this#type_params ~kind:Flow_ast_mapper.FunctionTP) tparams;
945945
expr
946946

947947
method! component_declaration loc (expr : ('loc, 'loc) Ast.Statement.ComponentDeclaration.t) =
@@ -955,7 +955,7 @@ end = struct
955955
~is_polymorphic:(Option.is_some tparams)
956956
~kind:Var
957957
(fun _ _ ->
958-
run_opt this#type_params tparams;
958+
run_opt (this#type_params ~kind:Flow_ast_mapper.ComponentDeclarationTP) tparams;
959959
run this#component_params params;
960960
run this#component_body body;
961961
run this#component_renders_annotation renders;
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,9 @@ class def_finder ~autocomplete_hooks ~react_jsx env_info toplevel_scope =
13481348
} =
13491349
stmt
13501350
in
1351-
Base.Option.iter component_tparams ~f:(fun tparams -> ignore @@ this#type_params tparams);
1351+
Base.Option.iter component_tparams ~f:(fun tparams ->
1352+
ignore @@ this#type_params ~kind:Flow_ast_mapper.ComponentDeclarationTP tparams
1353+
);
13521354
Base.List.iter ~f:this#visit_component_param params_list;
13531355
Base.Option.iter ~f:this#visit_component_rest_param rest;
13541356
ignore @@ this#component_renders_annotation renders;
@@ -1706,7 +1708,9 @@ class def_finder ~autocomplete_hooks ~react_jsx env_info toplevel_scope =
17061708
} =
17071709
expr
17081710
in
1709-
Base.Option.iter fun_tparams ~f:(fun tparams -> ignore @@ this#type_params tparams);
1711+
Base.Option.iter fun_tparams ~f:(fun tparams ->
1712+
ignore @@ (this#type_params ~kind:Flow_ast_mapper.FunctionTP) tparams
1713+
);
17101714
run_opt this#function_this_param this_;
17111715
let param_str_list = this#params_list_to_str_opt params_list in
17121716
let pred = this#hint_pred_kind params body return in
@@ -1799,7 +1803,7 @@ class def_finder ~autocomplete_hooks ~react_jsx env_info toplevel_scope =
17991803
this#in_scope
18001804
(fun () ->
18011805
run_opt this#class_identifier id;
1802-
run_opt this#type_params class_tparams;
1806+
run_opt (this#type_params ~kind:Flow_ast_mapper.ClassTP) class_tparams;
18031807
let this_tparam_loc = Base.Option.value_map ~default:loc ~f:fst id in
18041808
this#add_tparam this_tparam_loc "this";
18051809
ignore @@ this#class_body body;
@@ -2243,22 +2247,26 @@ class def_finder ~autocomplete_hooks ~react_jsx env_info toplevel_scope =
22432247
(OpaqueType (loc, otype));
22442248
this#in_new_tparams_env (fun () -> super#opaque_type loc otype)
22452249

2246-
method private visit_type_param ~from_infer_type (tparam : ('loc, 'loc) Ast.Type.TypeParam.t) =
2250+
method private visit_type_param
2251+
~from_infer_type ~kind (tparam : ('loc, 'loc) Ast.Type.TypeParam.t) =
22472252
let open Ast.Type.TypeParam in
22482253
let (_, { name = (name_loc, { Ast.Identifier.name; _ }); _ }) = tparam in
22492254
this#force_add_binding
22502255
(Env_api.OrdinaryNameLoc, name_loc)
22512256
(mk_reason (RType (OrdinaryName name)) name_loc)
22522257
(TypeParam { tparams_map = tparams; from_infer_type; tparam });
22532258
this#add_tparam name_loc name;
2254-
super#type_param tparam
2259+
super#type_param ~kind tparam
22552260

22562261
method! infer_type t =
22572262
let open Ast.Type.Infer in
22582263
let { tparam; comments } = t in
2259-
{ tparam = this#visit_type_param ~from_infer_type:true tparam; comments }
2264+
{
2265+
tparam = this#visit_type_param ~from_infer_type:true ~kind:Flow_ast_mapper.InferTP tparam;
2266+
comments;
2267+
}
22602268

2261-
method! type_param = this#visit_type_param ~from_infer_type:false
2269+
method! type_param ~kind = this#visit_type_param ~from_infer_type:false ~kind
22622270

22632271
method! interface loc (interface : ('loc, 'loc) Ast.Statement.Interface.t) =
22642272
let open Ast.Statement.Interface in
Original file line numberDiff line numberDiff line change
@@ -435,18 +435,18 @@ struct
435435
run this#function_params params;
436436
run_opt this#predicate predicate
437437
);
438-
run_opt this#type_params tparams
438+
run_opt (this#type_params ~kind:Flow_ast_mapper.FunctionTP) tparams
439439

440440
method component_def (expr : ('loc, 'loc) Ast.Statement.ComponentDeclaration.t) =
441441
let { Ast.Statement.ComponentDeclaration.params; renders; tparams; _ } = expr in
442442
run this#component_renders_annotation renders;
443443
run this#component_params_annotated params;
444-
run_opt this#type_params tparams
444+
run_opt (this#type_params ~kind:Flow_ast_mapper.ComponentDeclarationTP) tparams
445445

446446
method! declare_component _ (expr : ('loc, 'loc) Ast.Statement.DeclareComponent.t) =
447447
let { Ast.Statement.DeclareComponent.params; renders; tparams; _ } = expr in
448448
run this#component_renders_annotation renders;
449-
run_opt this#type_params tparams;
449+
run_opt (this#type_params ~kind:Flow_ast_mapper.DeclareComponentTP) tparams;
450450
run this#component_type_params params;
451451
expr
452452

@@ -880,7 +880,7 @@ struct
880880
Base.Option.iter ~f:visitor#class_extends_sig extends;
881881
run_opt visitor#class_implements implements;
882882
run_list visitor#class_decorator class_decorators;
883-
run_opt visitor#type_params tparams;
883+
run_opt (visitor#type_params ~kind:Flow_ast_mapper.ClassTP) tparams;
884884
())
885885
EnvMap.empty
886886
in
@@ -896,7 +896,7 @@ struct
896896
} =
897897
depends_of_node
898898
(fun visitor ->
899-
run_opt visitor#type_params tparams;
899+
run_opt (visitor#type_params ~kind:Flow_ast_mapper.DeclareClassTP) tparams;
900900
run_loc visitor#object_type body;
901901
run_loc_opt visitor#generic_type extends;
902902
Base.List.iter ~f:(run_loc visitor#generic_type) mixins;
@@ -924,15 +924,15 @@ struct
924924
let depends_of_alias { Ast.Statement.TypeAlias.tparams; right; _ } =
925925
depends_of_node
926926
(fun visitor ->
927-
run_opt visitor#type_params tparams;
927+
run_opt (visitor#type_params ~kind:Flow_ast_mapper.TypeAliasTP) tparams;
928928
run visitor#type_ right;
929929
())
930930
EnvMap.empty
931931
in
932932
let depends_of_opaque { Ast.Statement.OpaqueType.tparams; impltype; supertype; _ } =
933933
depends_of_node
934934
(fun visitor ->
935-
run_opt visitor#type_params tparams;
935+
run_opt (visitor#type_params ~kind:Flow_ast_mapper.OpaqueTypeTP) tparams;
936936
run_opt visitor#type_ impltype;
937937
run_opt visitor#type_ supertype;
938938
())
@@ -950,7 +950,7 @@ struct
950950
let depends_of_interface { Ast.Statement.Interface.tparams; extends; body; _ } =
951951
depends_of_node
952952
(fun visitor ->
953-
run_opt visitor#type_params tparams;
953+
run_opt (visitor#type_params ~kind:Flow_ast_mapper.InterfaceTP) tparams;
954954
Base.List.iter ~f:(run_loc visitor#generic_type) extends;
955955
run_loc visitor#object_type body;
956956
())
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ class selection_range_finder ~position =
161161

162162
method! type_args x = this#test super#type_args x
163163

164-
method! type_params x = this#test super#type_params x
164+
method! type_params ~kind x = this#test (super#type_params ~kind) x
165165

166-
method! type_param x = this#test super#type_param x
166+
method! type_param ~kind x = this#test (super#type_param ~kind) x
167167

168168
method! type_ x = this#test super#type_ x
169169

Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ class ['loc] trailing_comments_remover ~after_pos =
335335
let { comments; _ } = expr in
336336
id this#syntax_opt comments expr (fun comments' -> { expr with comments = comments' })
337337

338-
method! type_params tparams =
338+
method! type_params ~kind:_ tparams =
339339
let open Ast.Type.TypeParams in
340340
let (loc, { params; comments }) = tparams in
341341
id this#syntax_opt comments tparams (fun comments' -> (loc, { params; comments = comments' }))
@@ -437,12 +437,12 @@ let block_remove_trailing env block =
437437
let { remove_trailing; _ } = trailing_and_remover env in
438438
remove_trailing block (fun remover (loc, str) -> (loc, remover#block loc str))
439439

440-
let type_params_remove_trailing env tparams =
440+
let type_params_remove_trailing env ~kind tparams =
441441
match tparams with
442442
| None -> None
443443
| Some tparams ->
444444
let { remove_trailing; _ } = trailing_and_remover env in
445-
Some (remove_trailing tparams (fun remover tparams -> remover#type_params tparams))
445+
Some (remove_trailing tparams (fun remover tparams -> remover#type_params ~kind tparams))
446446

447447
let type_remove_trailing env ty =
448448
let { remove_trailing; _ } = trailing_and_remover env in
@@ -830,9 +830,9 @@ let call_type_arg_comment_bounds loc arg =
830830
ignore (collector#call_type_arg arg);
831831
collect_without_trailing_line_comment collector
832832

833-
let type_param_comment_bounds (loc, param) =
833+
let type_param_comment_bounds ~kind (loc, param) =
834834
let collector = new comment_bounds_collector ~loc in
835-
ignore (collector#type_param (loc, param));
835+
ignore (collector#type_param ~kind (loc, param));
836836
collect_without_trailing_line_comment collector
837837

838838
let function_body_comment_bounds body =
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,12 @@ module Declaration (Parse : Parser_common.PARSER) (Type : Parser_common.TYPE) :
331331
match (in_export_default env, Peek.token env) with
332332
| (true, T_LPAREN) -> (None, None)
333333
| (true, T_LESS_THAN) ->
334-
let tparams = type_params_remove_trailing env (Type.type_params env) in
334+
let tparams =
335+
type_params_remove_trailing
336+
env
337+
~kind:Flow_ast_mapper.DeclareFunctionTP
338+
(Type.type_params env)
339+
in
335340
let id =
336341
if Peek.token env = T_LPAREN then
337342
None
@@ -356,7 +361,12 @@ module Declaration (Parse : Parser_common.PARSER) (Type : Parser_common.TYPE) :
356361
(Peek.loc env, { Identifier.name = ""; comments = None })
357362
)
358363
in
359-
let tparams = type_params_remove_trailing env (Type.type_params env) in
364+
let tparams =
365+
type_params_remove_trailing
366+
env
367+
~kind:Flow_ast_mapper.DeclareFunctionTP
368+
(Type.type_params env)
369+
in
360370
(tparams, Some id)
361371
in
362372
let params =
@@ -596,7 +606,12 @@ module Declaration (Parse : Parser_common.PARSER) (Type : Parser_common.TYPE) :
596606
(* Components should have at least the same strictness as functions *)
597607
(Parse.identifier ~restricted_error:Parse_error.StrictFunctionName env)
598608
in
599-
let tparams = type_params_remove_trailing env (Type.type_params env) in
609+
let tparams =
610+
type_params_remove_trailing
611+
env
612+
~kind:Flow_ast_mapper.DeclareComponentTP
613+
(Type.type_params env)
614+
in
600615
let params =
601616
let params = component_params env in
602617
if Peek.is_renders_ident env then
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,12 @@ module Expression
11521152
in
11531153
Some id
11541154
in
1155-
let tparams = type_params_remove_trailing env (Type.type_params env) in
1155+
let tparams =
1156+
type_params_remove_trailing
1157+
env
1158+
~kind:Flow_ast_mapper.FunctionTP
1159+
(Type.type_params env)
1160+
in
11561161
(id, tparams)
11571162
in
11581163
(* #sec-function-definitions-static-semantics-early-errors *)
@@ -1777,7 +1782,9 @@ module Expression
17771782
let (sig_loc, (tparams, params, return, predicate)) =
17781783
with_loc
17791784
(fun env ->
1780-
let tparams = type_params_remove_trailing env (Type.type_params env) in
1785+
let tparams =
1786+
type_params_remove_trailing env ~kind:Flow_ast_mapper.FunctionTP (Type.type_params env)
1787+
in
17811788
(* Disallow all fancy features for identifier => body *)
17821789
if Peek.is_identifier env && tparams = None then
17831790
let ((loc, _) as name) =

0 commit comments

Comments
 (0)