@@ -540,6 +540,22 @@ and expression_desc cxt ~(level : int) f x : cxt =
540
540
| _ -> Some (f, x))
541
541
in
542
542
print_jsx cxt ~level f tag fields
543
+ | [
544
+ tag;
545
+ {
546
+ expression_desc =
547
+ Caml_block (el, _mutable_flag, _, Lambda. Blk_record {fields});
548
+ };
549
+ key;
550
+ ] ->
551
+ let fields =
552
+ Ext_list. array_list_filter_map fields el (fun (f , opt ) x ->
553
+ match x.expression_desc with
554
+ | Undefined _ when opt -> None
555
+ | _ -> Some (f, x))
556
+ in
557
+ let fields = (" key" , key) :: fields in
558
+ print_jsx cxt ~level f tag fields
543
559
| _ ->
544
560
expression_desc cxt ~level f
545
561
(Call
@@ -1033,19 +1049,50 @@ and expression_desc cxt ~(level : int) f x : cxt =
1033
1049
1034
1050
and print_jsx cxt ~(level : int ) f (tag : J.expression )
1035
1051
(fields : (string * J.expression) list ) : cxt =
1036
- ignore (level, tag, fields);
1052
+ let print_tag () =
1053
+ match tag.expression_desc with
1054
+ | J. Str {txt} -> P. string f txt
1055
+ | _ ->
1056
+ let _ = expression ~level cxt f tag in
1057
+ ()
1058
+ in
1037
1059
let children_opt =
1038
1060
List. find_map (fun (n , e ) -> if n = " children" then Some e else None ) fields
1039
1061
in
1062
+ let print_props () =
1063
+ let props = List. filter (fun (n , _ ) -> n <> " children" ) fields in
1064
+ if not (List. is_empty props) then
1065
+ (List. iter (fun (n , x ) ->
1066
+ P. space f;
1067
+ P. string f n;
1068
+ P. string f " =" ;
1069
+ P. string f " {" ;
1070
+ let _ = expression ~level: 0 cxt f x in
1071
+ P. string f " }" ))
1072
+ props
1073
+ in
1040
1074
(match children_opt with
1041
- | None -> P. string f " < />"
1075
+ | None ->
1076
+ P. string f " <" ;
1077
+ print_tag () ;
1078
+ print_props () ;
1079
+ P. string f " />"
1042
1080
| Some children ->
1081
+ let child_is_jsx =
1082
+ match children.expression_desc with
1083
+ | J. Call (_ , _ , {call_transformed_jsx = Some _ } ) -> true
1084
+ | _ -> false
1085
+ in
1086
+
1043
1087
P. string f " <" ;
1044
- let _ = expression ~level cxt f tag in
1088
+ print_tag () ;
1089
+ print_props () ;
1045
1090
P. string f " >" ;
1091
+ if not child_is_jsx then P. string f " {" ;
1046
1092
let _ = expression ~level cxt f children in
1093
+ if not child_is_jsx then P. string f " }" ;
1047
1094
P. string f " </" ;
1048
- let _ = expression ~level cxt f tag in
1095
+ print_tag () ;
1049
1096
P. string f " >" );
1050
1097
1051
1098
cxt
0 commit comments