@@ -524,7 +524,10 @@ and expression_desc cxt ~(level : int) f x : cxt =
524
524
when Ext_list.length_equal el i
525
525
]}
526
526
*)
527
- | Call (e , el , {call_transformed_jsx = true } ) -> (
527
+ | Call
528
+ ( ({expression_desc = J. Var (J. Qualified (_, Some fnName))} as e),
529
+ el,
530
+ {call_transformed_jsx = true } ) -> (
528
531
match el with
529
532
| [
530
533
tag;
@@ -539,7 +542,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
539
542
| Undefined _ when opt -> None
540
543
| _ -> Some (f, x))
541
544
in
542
- print_jsx cxt ~level f tag fields
545
+ print_jsx cxt ~level f fnName tag fields
543
546
| [
544
547
tag;
545
548
{
@@ -555,7 +558,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
555
558
| _ -> Some (f, x))
556
559
in
557
560
let fields = (" key" , key) :: fields in
558
- print_jsx cxt ~level f tag fields
561
+ print_jsx cxt ~level f fnName tag fields
559
562
| _ ->
560
563
expression_desc cxt ~level f
561
564
(Call
@@ -996,7 +999,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
996
999
P. string f " ..." ;
997
1000
expression ~level: 13 cxt f e)
998
1001
999
- and print_jsx cxt ~(level : int ) f (tag : J.expression )
1002
+ and print_jsx cxt ~(level : int ) f (fnName : string ) ( tag : J.expression )
1000
1003
(fields : (string * J.expression) list ) : cxt =
1001
1004
let print_tag () =
1002
1005
match tag.expression_desc with
@@ -1008,7 +1011,17 @@ and print_jsx cxt ~(level : int) f (tag : J.expression)
1008
1011
()
1009
1012
in
1010
1013
let children_opt =
1011
- List. find_map (fun (n , e ) -> if n = " children" then Some e else None ) fields
1014
+ List. find_map
1015
+ (fun (n , e ) ->
1016
+ if n = " children" then
1017
+ if fnName = " jsxs" then
1018
+ match e.J. expression_desc with
1019
+ | J. Optional_block ({expression_desc = J. Array (xs , _ )} , _ ) ->
1020
+ Some xs
1021
+ | _ -> Some [e]
1022
+ else Some [e]
1023
+ else None )
1024
+ fields
1012
1025
in
1013
1026
let print_props () =
1014
1027
let props = List. filter (fun (n , _ ) -> n <> " children" ) fields in
@@ -1029,8 +1042,8 @@ and print_jsx cxt ~(level : int) f (tag : J.expression)
1029
1042
print_props () ;
1030
1043
P. string f " />"
1031
1044
| Some children ->
1032
- let child_is_jsx =
1033
- match children .expression_desc with
1045
+ let child_is_jsx child =
1046
+ match child. J . expression_desc with
1034
1047
| J. Call (_ , _ , {call_transformed_jsx = is_jsx } ) -> is_jsx
1035
1048
| _ -> false
1036
1049
in
@@ -1039,9 +1052,18 @@ and print_jsx cxt ~(level : int) f (tag : J.expression)
1039
1052
print_tag () ;
1040
1053
print_props () ;
1041
1054
P. string f " >" ;
1042
- if not child_is_jsx then P. string f " {" ;
1043
- let _ = expression ~level cxt f children in
1044
- if not child_is_jsx then P. string f " }" ;
1055
+
1056
+ let _ =
1057
+ children
1058
+ |> List. fold_left
1059
+ (fun acc e ->
1060
+ if not (child_is_jsx e) then P. string f " {" ;
1061
+ let next = expression ~level acc f e in
1062
+ if not (child_is_jsx e) then P. string f " }" ;
1063
+ next)
1064
+ cxt
1065
+ in
1066
+
1045
1067
P. string f " </" ;
1046
1068
print_tag () ;
1047
1069
P. string f " >" );
0 commit comments