Skip to content

Commit f1b4687

Browse files
committed
Print props, catch with key functions
1 parent 4af3986 commit f1b4687

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

compiler/core/js_dump.ml

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,22 @@ and expression_desc cxt ~(level : int) f x : cxt =
540540
| _ -> Some (f, x))
541541
in
542542
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
543559
| _ ->
544560
expression_desc cxt ~level f
545561
(Call
@@ -1033,19 +1049,50 @@ and expression_desc cxt ~(level : int) f x : cxt =
10331049

10341050
and print_jsx cxt ~(level : int) f (tag : J.expression)
10351051
(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
10371059
let children_opt =
10381060
List.find_map (fun (n, e) -> if n = "children" then Some e else None) fields
10391061
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
10401074
(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 "/>"
10421080
| 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+
10431087
P.string f "<";
1044-
let _ = expression ~level cxt f tag in
1088+
print_tag ();
1089+
print_props ();
10451090
P.string f ">";
1091+
if not child_is_jsx then P.string f "{";
10461092
let _ = expression ~level cxt f children in
1093+
if not child_is_jsx then P.string f "}";
10471094
P.string f "</";
1048-
let _ = expression ~level cxt f tag in
1095+
print_tag ();
10491096
P.string f ">");
10501097

10511098
cxt

0 commit comments

Comments
 (0)