diff --git a/src/commands/commandUtils.ml b/src/commands/commandUtils.ml index b8f2804de62..d8f39685635 100644 --- a/src/commands/commandUtils.ml +++ b/src/commands/commandUtils.ml @@ -1378,7 +1378,6 @@ let make_options |> min Sys_utils.nbr_procs; opt_suppress_types = FlowConfig.suppress_types flowconfig; opt_max_literal_length = FlowConfig.max_literal_length flowconfig; - opt_as_const = Base.Option.value ~default:true (FlowConfig.enable_as_const flowconfig); opt_component_syntax = FlowConfig.component_syntax flowconfig; opt_react_rules = FlowConfig.react_rules flowconfig; opt_hook_compatibility = FlowConfig.hook_compatibility flowconfig; diff --git a/src/commands/config/flowConfig.ml b/src/commands/config/flowConfig.ml index b547a34b12c..3b255031e9b 100644 --- a/src/commands/config/flowConfig.ml +++ b/src/commands/config/flowConfig.ml @@ -59,7 +59,6 @@ module Opts = struct react_rules: Options.react_rules list; dev_only_refinement_info_as_errors: bool; emoji: bool option; - enable_as_const: bool option; enable_const_params: bool option; enums: bool; estimate_recheck_time: bool option; @@ -196,7 +195,6 @@ module Opts = struct react_rules = []; dev_only_refinement_info_as_errors = false; emoji = None; - enable_as_const = None; enable_const_params = None; enums = false; estimate_recheck_time = None; @@ -414,20 +412,6 @@ module Opts = struct ] (fun opts v -> Ok { opts with casting_syntax = Some v }) - let const_assertion_parser = - boolean (fun opts v -> - match opts.casting_syntax with - | None - | Some Options.CastingSyntax.As - | Some Options.CastingSyntax.Both -> - Ok { opts with enable_as_const = Some v } - | Some Options.CastingSyntax.Colon -> - Error - ("Setting \"as_const\" to true requires that \"casting_syntax\" " - ^ "is set to \"as\" or \"both\"." - ) - ) - let channel_mode_parser ~enabled = enum [("pipe", `pipe); ("socket", `socket)] @@ -998,7 +982,6 @@ module Opts = struct ("enums", boolean (fun opts v -> Ok { opts with enums = v })); ("estimate_recheck_time", estimate_recheck_time_parser); ("exact_by_default", boolean (fun opts v -> Ok { opts with exact_by_default = Some v })); - ("as_const", const_assertion_parser); ( "experimental.const_params", boolean (fun opts v -> Ok { opts with enable_const_params = Some v }) ); @@ -1707,8 +1690,6 @@ let dev_only_refinement_info_as_errors c = c.options.Opts.dev_only_refinement_in let emoji c = c.options.Opts.emoji -let enable_as_const c = c.options.Opts.enable_as_const - let enable_const_params c = c.options.Opts.enable_const_params let enums c = c.options.Opts.enums diff --git a/src/commands/config/flowConfig.mli b/src/commands/config/flowConfig.mli index 65504576bf5..7d885e5503a 100644 --- a/src/commands/config/flowConfig.mli +++ b/src/commands/config/flowConfig.mli @@ -96,8 +96,6 @@ val dev_only_refinement_info_as_errors : config -> bool val emoji : config -> bool option -val enable_as_const : config -> bool option - val enable_const_params : config -> bool option val enums : config -> bool diff --git a/src/common/options.ml b/src/common/options.ml index 9e37440908b..c01a2f1a4c1 100644 --- a/src/common/options.ml +++ b/src/common/options.ml @@ -73,7 +73,6 @@ end type t = { opt_all: bool; - opt_as_const: bool; opt_autoimports: bool; opt_autoimports_min_characters: int; opt_autoimports_ranked_by_usage: bool; @@ -170,8 +169,6 @@ type t = { let all opts = opts.opt_all -let as_const opts = opts.opt_as_const - let autoimports opts = opts.opt_autoimports let autoimports_min_characters opts = opts.opt_autoimports_min_characters diff --git a/src/flow_dot_js.ml b/src/flow_dot_js.ml index 08af5594c32..95519f186b7 100644 --- a/src/flow_dot_js.ml +++ b/src/flow_dot_js.ml @@ -110,7 +110,6 @@ let stub_metadata ~root ~checked = [ValidateRefAccessDuringRender; DeepReadOnlyProps; DeepReadOnlyHookReturns; RulesOfHooks]; react_rules_always = false; dev_only_refinement_info_as_errors = false; - enable_as_const = true; enable_const_params = false; enable_enums = true; enable_jest_integration = false; diff --git a/src/services/code_action/__tests__/refactor_extract_utils_tests.ml b/src/services/code_action/__tests__/refactor_extract_utils_tests.ml index 6cfca5af798..f75d4ff6c4c 100644 --- a/src/services/code_action/__tests__/refactor_extract_utils_tests.ml +++ b/src/services/code_action/__tests__/refactor_extract_utils_tests.ml @@ -43,7 +43,6 @@ let stub_metadata ~root ~checked = react_rules = []; react_rules_always = false; dev_only_refinement_info_as_errors = false; - enable_as_const = false; enable_const_params = false; enable_enums = true; enable_jest_integration = false; diff --git a/src/typing/__tests__/type_hint_test.ml b/src/typing/__tests__/type_hint_test.ml index e60e5c90428..d5e6283b27f 100644 --- a/src/typing/__tests__/type_hint_test.ml +++ b/src/typing/__tests__/type_hint_test.ml @@ -34,7 +34,6 @@ let metadata = react_rules = []; react_rules_always = false; dev_only_refinement_info_as_errors = false; - enable_as_const = false; enable_const_params = false; enable_enums = true; enable_jest_integration = false; diff --git a/src/typing/__tests__/typed_ast_test.ml b/src/typing/__tests__/typed_ast_test.ml index b3d18f91b64..e655de9a9cc 100644 --- a/src/typing/__tests__/typed_ast_test.ml +++ b/src/typing/__tests__/typed_ast_test.ml @@ -32,7 +32,6 @@ let metadata = react_rules = []; react_rules_always = false; dev_only_refinement_info_as_errors = false; - enable_as_const = false; enable_const_params = false; enable_enums = true; enable_jest_integration = false; diff --git a/src/typing/context.ml b/src/typing/context.ml index 03f7261e6b0..23eeb2df7f5 100644 --- a/src/typing/context.ml +++ b/src/typing/context.ml @@ -43,7 +43,6 @@ type metadata = { react_rules: Options.react_rules list; react_rules_always: bool; dev_only_refinement_info_as_errors: bool; - enable_as_const: bool; enable_const_params: bool; enable_enums: bool; enable_jest_integration: bool; @@ -271,7 +270,6 @@ let metadata_of_options options = react_rules = Options.react_rules options; react_rules_always = false; dev_only_refinement_info_as_errors = Options.dev_only_refinement_info_as_errors options; - enable_as_const = Options.as_const options; enable_const_params = Options.enable_const_params options; enable_enums = Options.enums options; enable_jest_integration = Options.enable_jest_integration options; @@ -485,8 +483,6 @@ let react_rule_enabled cx rule = List.mem rule cx.metadata.react_rules let dev_only_refinement_info_as_errors cx = cx.metadata.dev_only_refinement_info_as_errors -let enable_as_const cx = cx.metadata.enable_as_const - let enable_const_params cx = cx.metadata.enable_const_params || cx.metadata.strict || cx.metadata.strict_local diff --git a/src/typing/context.mli b/src/typing/context.mli index 921a6d5d0e9..04175e592f1 100644 --- a/src/typing/context.mli +++ b/src/typing/context.mli @@ -87,7 +87,6 @@ type metadata = { react_rules: Options.react_rules list; react_rules_always: bool; dev_only_refinement_info_as_errors: bool; - enable_as_const: bool; enable_const_params: bool; enable_enums: bool; enable_jest_integration: bool; @@ -183,8 +182,6 @@ val react_rules_always : t -> bool val dev_only_refinement_info_as_errors : t -> bool -val enable_as_const : t -> bool - val enable_const_params : t -> bool val enable_enums : t -> bool diff --git a/src/typing/errors/error_message.ml b/src/typing/errors/error_message.ml index 881a5dcd3d6..99d7211787e 100644 --- a/src/typing/errors/error_message.ml +++ b/src/typing/errors/error_message.ml @@ -716,7 +716,6 @@ and ts_syntax_kind = | TSTypeParamExtends | TSReadonlyVariance | TSInOutVariance of [ `In | `Out | `InOut ] - | TSAsConst of Options.CastingSyntax.t | TSSatisfiesType of Options.CastingSyntax.t | TSReadonlyType of [ `Tuple | `Array ] option @@ -2805,7 +2804,6 @@ let friendly_message_of_msg = function | TSInOutVariance `In -> Normal MessageTSVarianceIn | TSInOutVariance `Out -> Normal MessageTSVarianceOut | TSInOutVariance `InOut -> Normal MessageTSVarianceInOut - | TSAsConst enabled_casting_syntax -> Normal (MessageTSAsConst enabled_casting_syntax) | TSSatisfiesType enabled_casting_syntax -> Normal (MessageTSSatisfiesType enabled_casting_syntax) | TSReadonlyType (Some arg_kind) -> diff --git a/src/typing/errors/flow_intermediate_error.ml b/src/typing/errors/flow_intermediate_error.ml index c4d27ebca66..20942a194a1 100644 --- a/src/typing/errors/flow_intermediate_error.ml +++ b/src/typing/errors/flow_intermediate_error.ml @@ -3502,20 +3502,6 @@ let to_printable_error : text " inside object methods since these methods may be unbound and rebound."; ] @ suggestion - | MessageTSAsConst enabled_casting_syntax -> - let (example, _) = type_casting_examples enabled_casting_syntax in - [ - code "as const"; - text " syntax is not enabled by default. "; - text "Try adding a type annotation instead. "; - text "You can cast an expression to a type using the form "; - code example; - text ". "; - text "Alternatively, you can enable experimental support for "; - text "the feature by setting "; - code "as_const=true"; - text " in your flow config."; - ] | MessageTSKeyofType -> [ code "keyof"; diff --git a/src/typing/errors/flow_intermediate_error_types.ml b/src/typing/errors/flow_intermediate_error_types.ml index bf60378c96d..07374d4af69 100644 --- a/src/typing/errors/flow_intermediate_error_types.ml +++ b/src/typing/errors/flow_intermediate_error_types.ml @@ -812,7 +812,6 @@ type 'loc message = | MessageThisInComponent of 'loc | MessageThisInExportedFunction | MessageThisSuperInObject of 'loc virtual_reason * This_finder.kind - | MessageTSAsConst of Options.CastingSyntax.t | MessageTSKeyofType | MessageTSNeverType | MessageTSParamExtends diff --git a/src/typing/statement.ml b/src/typing/statement.ml index 6cb13620b25..1a7840e4e23 100644 --- a/src/typing/statement.ml +++ b/src/typing/statement.ml @@ -2780,16 +2780,10 @@ module Make (Error_message.EInvalidTypeCastSyntax { loc; enabled_casting_syntax = casting_syntax }); let t = AnyT.at (AnyError None) loc in ((loc, t), AsExpression (Tast_utils.error_mapper#as_expression cast))) - | AsConstExpression ({ AsConstExpression.expression = e; comments } as cast) -> - if Context.enable_as_const cx then ( - check_const_assertion cx e; - let (((_, t), _) as e) = expression cx ~as_const:true e in - ((loc, t), AsConstExpression { AsConstExpression.expression = e; comments }) - ) else - let kind = Error_message.TSAsConst (Context.casting_syntax cx) in - Flow_js_utils.add_output cx (Error_message.ETSSyntax { kind; loc }); - let t = AnyT.at (AnyError None) loc in - ((loc, t), AsConstExpression (Tast_utils.error_mapper#as_const_expression cast)) + | AsConstExpression { AsConstExpression.expression = e; comments } -> + check_const_assertion cx e; + let (((_, t), _) as e) = expression cx ~as_const:true e in + ((loc, t), AsConstExpression { AsConstExpression.expression = e; comments }) | TSSatisfies cast -> Flow_js_utils.add_output cx