From 35ad37854065360f086e98757cb4ee19bfa376b8 Mon Sep 17 00:00:00 2001 From: Sam Zhou Date: Thu, 12 Dec 2024 13:53:54 -0800 Subject: [PATCH] [flow][refactor] Make `CJSRequireTKit.on_ModuleT` and related functions accept labeled params instead of a tuple of random info Summary: Will do some refactor later. Changelog: [internal] Reviewed By: panagosg7 Differential Revision: D67154908 fbshipit-source-id: b031a85eea79c745c0968bc08740495cb546f1f5 --- src/typing/annotation_inference.ml | 16 +++++++++++++--- src/typing/flow_js_utils.ml | 2 +- src/typing/type_operation_utils.ml | 5 ++++- src/typing/type_sig_merge.ml | 4 ++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/typing/annotation_inference.ml b/src/typing/annotation_inference.ml index 7adb265df24..522ed87d118 100644 --- a/src/typing/annotation_inference.ml +++ b/src/typing/annotation_inference.ml @@ -99,7 +99,14 @@ module type S = sig val mk_sig_tvar : Context.t -> Reason.t -> Type.t Lazy.t -> Type.t - val cjs_require : Context.t -> Type.t -> Reason.t -> FlowSymbol.symbol -> bool -> bool -> Type.t + val cjs_require : + Context.t -> + Type.t -> + Reason.t -> + FlowSymbol.symbol -> + is_strict:bool -> + legacy_interop:bool -> + Type.t val export_named : Context.t -> @@ -669,7 +676,10 @@ module rec ConsGen : S = struct CJSRequireTKit.on_ModuleT cx ~reposition:(fun _ _ t -> t) - (reason, namespace_symbol, is_strict, legacy_interop) + ~reason + ~module_symbol:namespace_symbol + ~is_strict + ~legacy_interop m | (ModuleT m, Annot_ImportModuleNsT (reason, namespace_symbol, is_strict)) -> let (values_type, types_tmap) = ImportModuleNsTKit.on_ModuleT cx (reason, is_strict) m in @@ -1380,7 +1390,7 @@ module rec ConsGen : S = struct in mk_lazy_tvar cx reason f - and cjs_require cx t reason namespace_symbol is_strict legacy_interop = + and cjs_require cx t reason namespace_symbol ~is_strict ~legacy_interop = elab_t cx t (Annot_CJSRequireT { reason; namespace_symbol; is_strict; legacy_interop }) and export_named cx reason export_kind value_exports_tmap type_exports_tmap t = diff --git a/src/typing/flow_js_utils.ml b/src/typing/flow_js_utils.ml index 3d073b5eb7d..47ead9f8bc0 100644 --- a/src/typing/flow_js_utils.ml +++ b/src/typing/flow_js_utils.ml @@ -1518,7 +1518,7 @@ end module CJSRequireTKit = struct (* require('SomeModule') *) - let on_ModuleT cx ~reposition (reason, module_symbol, is_strict, legacy_interop) module_ = + let on_ModuleT cx ~reposition ~reason ~module_symbol ~is_strict ~legacy_interop module_ = let { module_reason; module_export_types = exports; diff --git a/src/typing/type_operation_utils.ml b/src/typing/type_operation_utils.ml index 26e4ba3aa24..be9a0f03b92 100644 --- a/src/typing/type_operation_utils.ml +++ b/src/typing/type_operation_utils.ml @@ -275,7 +275,10 @@ module Import_export = struct Flow_js_utils.CJSRequireTKit.on_ModuleT cx ~reposition:Flow.reposition - (reason, namespace_symbol, is_strict, legacy_interop) + ~reason + ~module_symbol:namespace_symbol + ~is_strict + ~legacy_interop m | Error (lreason, any_source) -> AnyT (lreason, any_source) end diff --git a/src/typing/type_sig_merge.ml b/src/typing/type_sig_merge.ml index ae4bc6f34ed..3e5f208c756 100644 --- a/src/typing/type_sig_merge.ml +++ b/src/typing/type_sig_merge.ml @@ -214,7 +214,7 @@ let require file loc index ~legacy_interop = let module_t = get_module_t loc resolved_require in let reason = Reason.(mk_reason (RModule mref) loc) in let symbol = FlowSymbol.mk_module_symbol ~name:mref ~def_loc:loc in - ConsGen.cjs_require file.cx module_t reason symbol false legacy_interop + ConsGen.cjs_require file.cx module_t reason symbol ~is_strict:false ~legacy_interop let import file reason id_loc index kind ~remote ~local = let (mref, (lazy resolved_require)) = Module_refs.get file.dependencies index in @@ -804,7 +804,7 @@ and merge_annot env file = function let module_t = Flow_js_utils.get_builtin_module file.cx ref loc in let reason = Reason.(mk_annot_reason (RModule ref) loc) in let symbol = FlowSymbol.mk_module_symbol ~name:ref ~def_loc:loc in - ConsGen.cjs_require file.cx module_t reason symbol false false + ConsGen.cjs_require file.cx module_t reason symbol ~is_strict:false ~legacy_interop:false | Conditional { loc; distributive_tparam; infer_tparams; check_type; extends_type; true_type; false_type } ->