Skip to content

Commit

Permalink
[flow][refactor] Move assert_export_is_type from ImportExport to …
Browse files Browse the repository at this point in the history
…`TypeAssertions` module

Summary:
Instead of leaving the only one behind, let's re-organize.

Changelog: [internal]

Reviewed By: gkz

Differential Revision: D69140885

fbshipit-source-id: bc5c9941a12b4797fcc0bd01f9c6c8c50421ace1
  • Loading branch information
SamChou19815 authored and facebook-github-bot committed Feb 5, 2025
1 parent 62ae57e commit 40c1e4b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/typing/statement.ml
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ module Make
let export_ref loc local_name =
let t = Type_env.var_ref ~lookup_mode cx local_name loc in
match export_kind with
| Ast.Statement.ExportType -> (None, Import_export.assert_export_is_type cx local_name t)
| Ast.Statement.ExportType -> (None, TypeAssertions.assert_export_is_type cx local_name t)
| Ast.Statement.ExportValue -> (None, t)
in
(* [declare] export [type] {foo [as bar]} from 'module' *)
Expand Down
24 changes: 11 additions & 13 deletions src/typing/type_operation_utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,6 @@ module DistributeUnionIntersection = struct
)
end

module Import_export = struct
let assert_export_is_type cx name t =
let reason = TypeUtil.reason_of_t t in
Tvar_resolver.mk_tvar_and_fully_resolve_where cx reason (fun tout ->
let t =
t
|> Flow.singleton_concretize_type_for_imports_exports cx reason
|> Flow_js_utils.AssertExportIsTypeTKit.on_concrete_type cx name
in
Flow.flow_t cx (t, tout)
)
end

module Operators = struct
let arith cx reason kind t1 t2 =
Tvar_resolver.mk_tvar_and_fully_resolve_where cx reason (fun tout ->
Expand Down Expand Up @@ -536,6 +523,17 @@ module TypeAssertions = struct
| l -> add_output cx (Error_message.EBinaryInRHS (reason_of_t l))
)

let assert_export_is_type cx name t =
let reason = TypeUtil.reason_of_t t in
Tvar_resolver.mk_tvar_and_fully_resolve_where cx reason (fun tout ->
let t =
t
|> Flow.singleton_concretize_type_for_imports_exports cx reason
|> Flow_js_utils.AssertExportIsTypeTKit.on_concrete_type cx name
in
Flow.flow_t cx (t, tout)
)

let assert_for_in_rhs cx t =
DistributeUnionIntersection.distribute
cx
Expand Down
6 changes: 2 additions & 4 deletions src/typing/type_operation_utils.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ module DistributeUnionIntersection : sig
unit
end

module Import_export : sig
val assert_export_is_type : Context.t -> Reason.name -> Type.t -> Type.t
end

module Operators : sig
val arith : Context.t -> reason -> Type.ArithKind.t -> Type.t -> Type.t -> Type.t

Expand Down Expand Up @@ -65,6 +61,8 @@ module TypeAssertions : sig

val assert_binary_in_rhs : Context.t -> Type.t -> unit

val assert_export_is_type : Context.t -> Reason.name -> Type.t -> Type.t

val assert_for_in_rhs : Context.t -> Type.t -> unit

val assert_non_component_like_base :
Expand Down

0 comments on commit 40c1e4b

Please sign in to comment.