@@ -543,6 +543,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
543543 | _ -> Some (f, x))
544544 in
545545 print_jsx cxt ~level f fnName tag fields
546+ (* jsxKeyed call *)
546547 | [
547548 tag;
548549 {
@@ -559,6 +560,9 @@ and expression_desc cxt ~(level : int) f x : cxt =
559560 in
560561 let fields = (" key" , key) :: fields in
561562 print_jsx cxt ~level f fnName tag fields
563+ (* In the case of prop spreading *)
564+ | [tag; ({expression_desc = J. Seq _} as props)] ->
565+ print_jsx_prop_spreading cxt ~level f fnName tag props
562566 | _ ->
563567 expression_desc cxt ~level f
564568 (Call
@@ -1069,6 +1073,71 @@ and print_jsx cxt ~(level : int) f (fnName : string) (tag : J.expression)
10691073
10701074 cxt
10711075
1076+ (* TODO: clean up the code , a lot of code is duplicated *)
1077+ and print_jsx_prop_spreading cxt ~level f fnName tag props =
1078+ (* TODO: the children as somewhere present in the props Seq *)
1079+ let print_tag () =
1080+ match tag.expression_desc with
1081+ | J. Str {txt} -> P. string f txt
1082+ (* fragment *)
1083+ | J. Var (J. Qualified ({id = {name = "JsxRuntime" } } , Some "Fragment" )) -> ()
1084+ | _ ->
1085+ let _ = expression ~level cxt f tag in
1086+ ()
1087+ in
1088+ (* let children_opt =
1089+ List.find_map
1090+ (fun (n, e) ->
1091+ if n = "children" then
1092+ if fnName = "jsxs" then
1093+ match e.J.expression_desc with
1094+ | J.Optional_block ({expression_desc = J.Array (xs, _)}, _) ->
1095+ Some xs
1096+ | _ -> Some [e]
1097+ else Some [e]
1098+ else None)
1099+ fields
1100+ in *)
1101+ let print_props () =
1102+ P. string f " {...(" ;
1103+ let _ = expression ~level: 0 cxt f props in
1104+ P. string f " )}"
1105+ in
1106+ (match None with
1107+ | None ->
1108+ P. string f " <" ;
1109+ print_tag () ;
1110+ print_props () ;
1111+ P. string f " />"
1112+ | Some children ->
1113+ let child_is_jsx child =
1114+ match child.J. expression_desc with
1115+ | J. Call (_ , _ , {call_transformed_jsx = is_jsx } ) -> is_jsx
1116+ | _ -> false
1117+ in
1118+
1119+ P. string f " <" ;
1120+ print_tag () ;
1121+ print_props () ;
1122+ P. string f " >" ;
1123+
1124+ let _ =
1125+ children
1126+ |> List. fold_left
1127+ (fun acc e ->
1128+ if not (child_is_jsx e) then P. string f " {" ;
1129+ let next = expression ~level acc f e in
1130+ if not (child_is_jsx e) then P. string f " }" ;
1131+ next)
1132+ cxt
1133+ in
1134+
1135+ P. string f " </" ;
1136+ print_tag () ;
1137+ P. string f " >" );
1138+
1139+ cxt
1140+
10721141and property_name_and_value_list cxt f (l : J.property_map ) =
10731142 iter_lst cxt f l
10741143 (fun cxt f (pn , e ) ->
0 commit comments