@@ -1109,10 +1109,6 @@ module type Import_export_helper_sig = sig
1109
1109
Type .t ->
1110
1110
Type .t
1111
1111
1112
- val assert_import_is_value : Context .t -> Type .trace -> Reason .t -> string -> Type .t -> unit
1113
-
1114
- val with_concretized_type : Context .t -> Reason .t -> (Type .t -> Type .t ) -> Type .t -> Type .t
1115
-
1116
1112
val export_named :
1117
1113
Context .t ->
1118
1114
Type .trace ->
@@ -1138,8 +1134,6 @@ module type Import_export_helper_sig = sig
1138
1134
Context .t -> Type .trace -> Reason .t * (Reason .t * Type .exporttypes * bool ) -> Type .t -> Type .t
1139
1135
1140
1136
val return : Context .t -> Type .trace -> Type .t -> r
1141
-
1142
- val mk_typeof_annotation : Context .t -> ?trace : Type .trace -> reason -> Type .t -> Type .t
1143
1137
end
1144
1138
1145
1139
(* ********************************************************************)
@@ -1175,7 +1169,7 @@ end
1175
1169
Overall, we should be able to (at least conceptually) desugar `import
1176
1170
type` to `import` followed by `type`.
1177
1171
*)
1178
- module ImportTypeT_kit ( F : Import_export_helper_sig ) = struct
1172
+ module ImportTypeTKit = struct
1179
1173
let canonicalize_imported_type cx reason t =
1180
1174
match t with
1181
1175
| DefT (_ , trust , ClassT inst ) -> Some (DefT (reason, trust, TypeT (ImportClassKind , inst)))
@@ -1209,18 +1203,15 @@ module ImportTypeT_kit (F : Import_export_helper_sig) = struct
1209
1203
| None ->
1210
1204
add_output cx ~trace (Error_message. EImportValueAsType (reason, export_name));
1211
1205
AnyT. error reason)
1212
-
1213
- let on_type cx trace reason export_name l =
1214
- F. with_concretized_type cx reason (on_concrete_type cx trace reason export_name) l
1215
1206
end
1216
1207
1217
1208
(* ***********************************************************************)
1218
1209
(* `import typeof` creates a properly-parameterized type alias for the *)
1219
1210
(* "typeof" the remote export. *)
1220
1211
(* ***********************************************************************)
1221
1212
1222
- module ImportTypeofT_kit ( F : Import_export_helper_sig ) = struct
1223
- let on_concrete_type cx trace reason export_name l =
1213
+ module ImportTypeofTKit = struct
1214
+ let on_concrete_type cx trace ~ mk_typeof_annotation reason export_name l =
1224
1215
match l with
1225
1216
| DefT
1226
1217
( _,
@@ -1233,7 +1224,7 @@ module ImportTypeofT_kit (F : Import_export_helper_sig) = struct
1233
1224
id;
1234
1225
}
1235
1226
) ->
1236
- let typeof_t = F. mk_typeof_annotation cx ~ trace reason lower_t in
1227
+ let typeof_t = mk_typeof_annotation cx ? trace:( Some trace) reason lower_t in
1237
1228
1238
1229
poly_type
1239
1230
id
@@ -1245,11 +1236,8 @@ module ImportTypeofT_kit (F : Import_export_helper_sig) = struct
1245
1236
add_output cx ~trace (Error_message. EImportTypeAsTypeof (reason, export_name));
1246
1237
AnyT. error reason
1247
1238
| _ ->
1248
- let typeof_t = F. mk_typeof_annotation cx ~ trace reason l in
1239
+ let typeof_t = mk_typeof_annotation cx ? trace:( Some trace) reason l in
1249
1240
DefT (reason, bogus_trust () , TypeT (ImportTypeofKind , typeof_t))
1250
-
1251
- let on_type cx trace reason export_name l =
1252
- F. with_concretized_type cx reason (on_concrete_type cx trace reason export_name) l
1253
1241
end
1254
1242
1255
1243
module CJSRequireT_kit (F : Import_export_helper_sig ) = struct
@@ -1325,14 +1313,14 @@ module ImportModuleNsTKit = struct
1325
1313
Obj_type. mk_with_proto cx reason ~obj_kind ~frozen: true ~props proto
1326
1314
end
1327
1315
1328
- module ImportDefaultT_kit (F : Import_export_helper_sig ) = struct
1329
- module ImportTypeTKit = ImportTypeT_kit (F )
1330
- module ImportTypeofTKit = ImportTypeofT_kit (F )
1331
-
1316
+ module ImportDefaultTKit = struct
1332
1317
(* import [type] X from 'SomeModule'; *)
1333
1318
let on_ModuleT
1334
1319
cx
1335
1320
trace
1321
+ ~mk_typeof_annotation
1322
+ ~assert_import_is_value
1323
+ ~with_concretized_type
1336
1324
(reason , import_kind , (local_name , module_name ), is_strict )
1337
1325
(module_reason , exports , imported_is_strict ) =
1338
1326
check_nonstrict_import cx trace is_strict imported_is_strict reason;
@@ -1366,21 +1354,31 @@ module ImportDefaultT_kit (F : Import_export_helper_sig) = struct
1366
1354
AnyT. error module_reason)
1367
1355
in
1368
1356
match import_kind with
1369
- | ImportType -> ImportTypeTKit. on_type cx trace reason " default" export_t
1370
- | ImportTypeof -> ImportTypeofTKit. on_type cx trace reason " default" export_t
1357
+ | ImportType ->
1358
+ with_concretized_type
1359
+ cx
1360
+ reason
1361
+ (ImportTypeTKit. on_concrete_type cx trace reason " default" )
1362
+ export_t
1363
+ | ImportTypeof ->
1364
+ with_concretized_type
1365
+ cx
1366
+ reason
1367
+ (ImportTypeofTKit. on_concrete_type cx trace ~mk_typeof_annotation reason " default" )
1368
+ export_t
1371
1369
| ImportValue ->
1372
- F. assert_import_is_value cx trace reason " default" export_t;
1370
+ assert_import_is_value cx trace reason " default" export_t;
1373
1371
export_t
1374
1372
end
1375
1373
1376
- module ImportNamedT_kit (F : Import_export_helper_sig ) = struct
1377
- module ImportTypeTKit = ImportTypeT_kit (F )
1378
- module ImportTypeofTKit = ImportTypeofT_kit (F )
1379
-
1374
+ module ImportNamedTKit = struct
1380
1375
(* import {X} from 'SomeModule'; *)
1381
1376
let on_ModuleT
1382
1377
cx
1383
1378
trace
1379
+ ~mk_typeof_annotation
1380
+ ~assert_import_is_value
1381
+ ~with_concretized_type
1384
1382
(reason , import_kind , export_name , module_name , is_strict )
1385
1383
(_ , exports , imported_is_strict ) =
1386
1384
check_nonstrict_import cx trace is_strict imported_is_strict reason;
@@ -1399,18 +1397,36 @@ module ImportNamedT_kit (F : Import_export_helper_sig) = struct
1399
1397
in
1400
1398
let has_every_named_export = exports.has_every_named_export in
1401
1399
match (import_kind, NameUtils.Map. find_opt (OrdinaryName export_name) exports_tmap) with
1402
- | (ImportType, Some t ) -> ImportTypeTKit. on_type cx trace reason export_name t
1400
+ | (ImportType, Some t ) ->
1401
+ with_concretized_type
1402
+ cx
1403
+ reason
1404
+ (ImportTypeTKit. on_concrete_type cx trace reason export_name)
1405
+ t
1403
1406
| (ImportType, None) when has_every_named_export ->
1404
- ImportTypeTKit. on_type cx trace reason export_name (AnyT. untyped reason)
1405
- | (ImportTypeof, Some t ) -> ImportTypeofTKit. on_type cx trace reason export_name t
1407
+ with_concretized_type
1408
+ cx
1409
+ reason
1410
+ (ImportTypeTKit. on_concrete_type cx trace reason export_name)
1411
+ (AnyT. untyped reason)
1412
+ | (ImportTypeof, Some t ) ->
1413
+ with_concretized_type
1414
+ cx
1415
+ reason
1416
+ (ImportTypeofTKit. on_concrete_type cx trace ~mk_typeof_annotation reason export_name)
1417
+ t
1406
1418
| (ImportTypeof, None) when has_every_named_export ->
1407
- ImportTypeofTKit. on_type cx trace reason export_name (AnyT. untyped reason)
1419
+ with_concretized_type
1420
+ cx
1421
+ reason
1422
+ (ImportTypeofTKit. on_concrete_type cx trace ~mk_typeof_annotation reason export_name)
1423
+ (AnyT. untyped reason)
1408
1424
| (ImportValue, Some t ) ->
1409
- F. assert_import_is_value cx trace reason export_name t;
1425
+ assert_import_is_value cx trace reason export_name t;
1410
1426
t
1411
1427
| (ImportValue, None) when has_every_named_export ->
1412
1428
let t = AnyT. untyped reason in
1413
- F. assert_import_is_value cx trace reason export_name t;
1429
+ assert_import_is_value cx trace reason export_name t;
1414
1430
t
1415
1431
| (_ , None) ->
1416
1432
let num_exports = NameUtils.Map. cardinal exports_tmap in
@@ -1579,8 +1595,6 @@ end
1579
1595
* exports one type at a time and it takes the type to be exported as a
1580
1596
* lower (so that the type can be filtered post-resolution). *)
1581
1597
module ExportTypeT_kit (F : Import_export_helper_sig ) = struct
1582
- module ImportTypeTKit = ImportTypeT_kit (F )
1583
-
1584
1598
let on_concrete_type cx trace (reason , export_name , target_module_t ) l =
1585
1599
let is_type_export =
1586
1600
match l with
0 commit comments