Skip to content

Commit

Permalink
[flow][refactor] Make CJSRequireTKit.on_ModuleT and related functio…
Browse files Browse the repository at this point in the history
…ns 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
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Dec 12, 2024
1 parent 8215548 commit 35ad378
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
16 changes: 13 additions & 3 deletions src/typing/annotation_inference.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion src/typing/flow_js_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/typing/type_operation_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/typing/type_sig_merge.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }
->
Expand Down

0 comments on commit 35ad378

Please sign in to comment.