Skip to content

Commit 44f24c9

Browse files
committed
Extract collect_prop_types helper
1 parent 697cb33 commit 44f24c9

File tree

1 file changed

+13
-37
lines changed

1 file changed

+13
-37
lines changed

compiler/syntax/src/jsx_v4.ml

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,17 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
936936
new_binding )
937937
else (None, binding, None)
938938

939+
let rec collect_prop_types types ({ptyp_loc; ptyp_desc} as full_type) =
940+
match ptyp_desc with
941+
| Ptyp_arrow {arg; ret = {ptyp_desc = Ptyp_arrow _} as rest}
942+
when is_labelled arg.lbl || is_optional arg.lbl ->
943+
collect_prop_types ((arg.lbl, arg.attrs, ptyp_loc, arg.typ) :: types) rest
944+
| Ptyp_arrow {arg = {lbl = Nolabel}; ret} -> collect_prop_types types ret
945+
| Ptyp_arrow {arg; ret = return_value}
946+
when is_labelled arg.lbl || is_optional arg.lbl ->
947+
(return_value, (arg.lbl, arg.attrs, return_value.ptyp_loc, arg.typ) :: types)
948+
| _ -> (full_type, types)
949+
939950
let transform_structure_item ~config item =
940951
match item with
941952
(* external *)
@@ -968,19 +979,7 @@ let transform_structure_item ~config item =
968979
|> Option.map Jsx_common.typ_vars_of_core_type
969980
|> Option.value ~default:[]
970981
in
971-
let rec get_prop_types types ({ptyp_loc; ptyp_desc} as full_type) =
972-
match ptyp_desc with
973-
| Ptyp_arrow {arg; ret = {ptyp_desc = Ptyp_arrow _} as typ2}
974-
when is_labelled arg.lbl || is_optional arg.lbl ->
975-
get_prop_types ((arg.lbl, arg.attrs, ptyp_loc, arg.typ) :: types) typ2
976-
| Ptyp_arrow {arg = {lbl = Nolabel}; ret} -> get_prop_types types ret
977-
| Ptyp_arrow {arg; ret = return_value}
978-
when is_labelled arg.lbl || is_optional arg.lbl ->
979-
( return_value,
980-
(arg.lbl, arg.attrs, return_value.ptyp_loc, arg.typ) :: types )
981-
| _ -> (full_type, types)
982-
in
983-
let _, prop_types = get_prop_types [] pval_type in
982+
let _, prop_types = collect_prop_types [] pval_type in
984983
let named_type_list = List.fold_left arg_to_concrete_type [] prop_types in
985984
let ret_props_type =
986985
Typ.constr ~loc:pstr_loc
@@ -1069,30 +1068,7 @@ let transform_signature_item ~config item =
10691068
|> Option.map Jsx_common.typ_vars_of_core_type
10701069
|> Option.value ~default:[]
10711070
in
1072-
let rec get_prop_types types ({ptyp_loc; ptyp_desc} as full_type) =
1073-
match ptyp_desc with
1074-
| Ptyp_arrow {arg; ret = {ptyp_desc = Ptyp_arrow _} as rest}
1075-
when is_optional arg.lbl || is_labelled arg.lbl ->
1076-
get_prop_types ((arg.lbl, arg.attrs, ptyp_loc, arg.typ) :: types) rest
1077-
| Ptyp_arrow
1078-
{
1079-
arg =
1080-
{
1081-
lbl = Nolabel;
1082-
typ = {ptyp_desc = Ptyp_constr ({txt = Lident "unit"}, _)};
1083-
};
1084-
ret = rest;
1085-
} ->
1086-
get_prop_types types rest
1087-
| Ptyp_arrow {arg = {lbl = Nolabel}; ret = rest} ->
1088-
get_prop_types types rest
1089-
| Ptyp_arrow {arg; ret = return_value}
1090-
when is_optional arg.lbl || is_labelled arg.lbl ->
1091-
( return_value,
1092-
(arg.lbl, arg.attrs, return_value.ptyp_loc, arg.typ) :: types )
1093-
| _ -> (full_type, types)
1094-
in
1095-
let _, prop_types = get_prop_types [] pval_type in
1071+
let _, prop_types = collect_prop_types [] pval_type in
10961072
let named_type_list = List.fold_left arg_to_concrete_type [] prop_types in
10971073
let ret_props_type =
10981074
Typ.constr

0 commit comments

Comments
 (0)