File tree

11 files changed

+32
-6
lines changed

11 files changed

+32
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,7 @@ let make_options
13981398
|> min Sys_utils.nbr_procs;
13991399
opt_suppress_types = FlowConfig.suppress_types flowconfig;
14001400
opt_max_literal_length = FlowConfig.max_literal_length flowconfig;
1401+
opt_const_type_params = FlowConfig.enable_const_type_params flowconfig;
14011402
opt_component_syntax = FlowConfig.component_syntax flowconfig;
14021403
opt_react_rules = FlowConfig.react_rules flowconfig;
14031404
opt_hook_compatibility = FlowConfig.hook_compatibility flowconfig;
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ module Opts = struct
5656
component_syntax: bool;
5757
dev_only_refinement_info_as_errors: bool;
5858
emoji: bool option;
59+
enable_const_type_params: bool;
5960
enable_const_params: bool option;
6061
enums: bool;
6162
estimate_recheck_time: bool option;
@@ -196,6 +197,7 @@ module Opts = struct
196197
component_syntax = false;
197198
dev_only_refinement_info_as_errors = false;
198199
emoji = None;
200+
enable_const_type_params = false;
199201
enable_const_params = None;
200202
enums = false;
201203
estimate_recheck_time = None;
@@ -1028,6 +1030,9 @@ module Opts = struct
10281030
( "dev_only.refinement_info_as_errors",
10291031
boolean (fun opts v -> Ok { opts with dev_only_refinement_info_as_errors = v })
10301032
);
1033+
( "experimental.const_type_params",
1034+
boolean (fun opts v -> Ok { opts with enable_const_type_params = v })
1035+
);
10311036
("emoji", boolean (fun opts v -> Ok { opts with emoji = Some v }));
10321037
("enums", boolean (fun opts v -> Ok { opts with enums = v }));
10331038
("estimate_recheck_time", estimate_recheck_time_parser);
@@ -1830,6 +1835,8 @@ let dev_only_refinement_info_as_errors c = c.options.Opts.dev_only_refinement_in
18301835

18311836
let emoji c = c.options.Opts.emoji
18321837

1838+
let enable_const_type_params c = c.options.Opts.enable_const_type_params
1839+
18331840
let enable_const_params c = c.options.Opts.enable_const_params
18341841

18351842
let enums c = c.options.Opts.enums
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ val dev_only_refinement_info_as_errors : config -> bool
9090

9191
val emoji : config -> bool option
9292

93+
val enable_const_type_params : config -> bool
94+
9395
val enable_const_params : config -> bool option
9496

9597
val enums : config -> bool
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type t = {
8888
opt_casting_syntax: CastingSyntax.t;
8989
opt_channel_mode: [ `pipe | `socket ];
9090
opt_component_syntax: bool;
91+
opt_const_type_params: bool;
9192
opt_hook_compatibility_includes: Str.regexp list;
9293
opt_hook_compatibility_excludes: Str.regexp list;
9394
opt_hook_compatibility: bool;
@@ -198,6 +199,8 @@ let channel_mode opts = opts.opt_channel_mode
198199

199200
let component_syntax opts = opts.opt_component_syntax
200201

202+
let const_type_params opts = opts.opt_const_type_params
203+
201204
let hook_compatibility opts = opts.opt_hook_compatibility
202205

203206
let hook_compatibility_includes opts = opts.opt_hook_compatibility_includes
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ let stub_metadata ~root ~checked =
113113
[ValidateRefAccessDuringRender; DeepReadOnlyProps; DeepReadOnlyHookReturns; RulesOfHooks];
114114
react_rules_always = false;
115115
dev_only_refinement_info_as_errors = false;
116+
enable_const_type_params = false;
116117
enable_const_params = false;
117118
enable_enums = true;
118119
enable_jest_integration = false;
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ let stub_metadata ~root ~checked =
3939
react_rules = [];
4040
react_rules_always = false;
4141
dev_only_refinement_info_as_errors = false;
42+
enable_const_type_params = false;
4243
enable_const_params = false;
4344
enable_enums = true;
4445
enable_jest_integration = false;
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ let metadata =
3434
react_rules = [];
3535
react_rules_always = false;
3636
dev_only_refinement_info_as_errors = false;
37+
enable_const_type_params = false;
3738
enable_const_params = false;
3839
enable_enums = true;
3940
enable_jest_integration = false;
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ let metadata =
3232
react_rules = [];
3333
react_rules_always = false;
3434
dev_only_refinement_info_as_errors = false;
35+
enable_const_type_params = false;
3536
enable_const_params = false;
3637
enable_enums = true;
3738
enable_jest_integration = false;
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type metadata = {
4343
react_rules: Options.react_rules list;
4444
react_rules_always: bool;
4545
dev_only_refinement_info_as_errors: bool;
46+
enable_const_type_params: bool;
4647
enable_const_params: bool;
4748
enable_enums: bool;
4849
enable_jest_integration: bool;
@@ -286,6 +287,7 @@ let metadata_of_options options =
286287
react_rules = Options.react_rules options;
287288
react_rules_always = false;
288289
dev_only_refinement_info_as_errors = Options.dev_only_refinement_info_as_errors options;
290+
enable_const_type_params = Options.const_type_params options;
289291
enable_const_params = Options.enable_const_params options;
290292
enable_enums = Options.enums options;
291293
enable_jest_integration = Options.enable_jest_integration options;
@@ -538,6 +540,8 @@ let react_rule_enabled cx rule = List.mem rule cx.metadata.react_rules
538540

539541
let dev_only_refinement_info_as_errors cx = cx.metadata.dev_only_refinement_info_as_errors
540542

543+
let enable_const_type_params cx = cx.metadata.enable_const_type_params
544+
541545
let enable_const_params cx =
542546
cx.metadata.enable_const_params || cx.metadata.strict || cx.metadata.strict_local
543547

Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type metadata = {
9393
react_rules: Options.react_rules list;
9494
react_rules_always: bool;
9595
dev_only_refinement_info_as_errors: bool;
96+
enable_const_type_params: bool;
9697
enable_const_params: bool;
9798
enable_enums: bool;
9899
enable_jest_integration: bool;
@@ -200,6 +201,8 @@ val react_rules_always : t -> bool
200201

201202
val dev_only_refinement_info_as_errors : t -> bool
202203

204+
val enable_const_type_params : t -> bool
205+
203206
val enable_const_params : t -> bool
204207

205208
val enable_enums : t -> bool
Original file line numberDiff line numberDiff line change
@@ -2562,12 +2562,14 @@ module Make (Statement : Statement_sig.S) : Type_annotation_sig.S = struct
25622562
in
25632563
let reason = mk_annot_reason (RType (OrdinaryName name)) name_loc in
25642564
let polarity = polarity cx variance in
2565-
Base.Option.iter const ~f:(fun (loc, _) ->
2566-
Flow_js_utils.add_output
2567-
env.cx
2568-
(Error_message.EUnsupportedSyntax (loc, Flow_intermediate_error_types.ConstTypeParameter)
2569-
)
2570-
);
2565+
if not (Context.enable_const_type_params cx) then
2566+
Base.Option.iter const ~f:(fun (loc, _) ->
2567+
Flow_js_utils.add_output
2568+
env.cx
2569+
(Error_message.EUnsupportedSyntax
2570+
(loc, Flow_intermediate_error_types.ConstTypeParameter)
2571+
)
2572+
);
25712573
(match bound_kind with
25722574
| Ast.Type.TypeParam.Extends when not (kind = Flow_ast_mapper.InferTP || Context.ts_syntax cx)
25732575
->

0 commit comments

Comments
 (0)