Skip to content

Commit 3d2930e

Browse files
committed
Unwrap children
1 parent d0bfedc commit 3d2930e

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

compiler/core/js_dump.ml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,10 @@ and expression_desc cxt ~(level : int) f x : cxt =
524524
when Ext_list.length_equal el i
525525
]}
526526
*)
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} ) -> (
528531
match el with
529532
| [
530533
tag;
@@ -539,7 +542,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
539542
| Undefined _ when opt -> None
540543
| _ -> Some (f, x))
541544
in
542-
print_jsx cxt ~level f tag fields
545+
print_jsx cxt ~level f fnName tag fields
543546
| [
544547
tag;
545548
{
@@ -555,7 +558,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
555558
| _ -> Some (f, x))
556559
in
557560
let fields = ("key", key) :: fields in
558-
print_jsx cxt ~level f tag fields
561+
print_jsx cxt ~level f fnName tag fields
559562
| _ ->
560563
expression_desc cxt ~level f
561564
(Call
@@ -996,7 +999,7 @@ and expression_desc cxt ~(level : int) f x : cxt =
996999
P.string f "...";
9971000
expression ~level:13 cxt f e)
9981001

999-
and print_jsx cxt ~(level : int) f (tag : J.expression)
1002+
and print_jsx cxt ~(level : int) f (fnName : string) (tag : J.expression)
10001003
(fields : (string * J.expression) list) : cxt =
10011004
let print_tag () =
10021005
match tag.expression_desc with
@@ -1008,7 +1011,17 @@ and print_jsx cxt ~(level : int) f (tag : J.expression)
10081011
()
10091012
in
10101013
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
10121025
in
10131026
let print_props () =
10141027
let props = List.filter (fun (n, _) -> n <> "children") fields in
@@ -1029,8 +1042,8 @@ and print_jsx cxt ~(level : int) f (tag : J.expression)
10291042
print_props ();
10301043
P.string f "/>"
10311044
| 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
10341047
| J.Call (_, _, {call_transformed_jsx = is_jsx}) -> is_jsx
10351048
| _ -> false
10361049
in
@@ -1039,9 +1052,18 @@ and print_jsx cxt ~(level : int) f (tag : J.expression)
10391052
print_tag ();
10401053
print_props ();
10411054
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+
10451067
P.string f "</";
10461068
print_tag ();
10471069
P.string f ">");

compiler/core/jsx_help.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ let j_exp_to_string (e : J.expression) =
1717
match e.J.expression_desc with
1818
| J.Object _ -> "Object"
1919
| J.Str _ -> "String"
20+
| J.Var (J.Qualified (_, Some o)) -> "Var_" ^ o
2021
| J.Var _ -> "Var"
2122
| J.Call _ -> "Call"
2223
| J.Fun _ -> "Fun"

0 commit comments

Comments
 (0)