Skip to content

Commit 1801da1

Browse files
committed
WIP extract, good stuff
1 parent a98e3b8 commit 1801da1

File tree

1 file changed

+71
-48
lines changed

1 file changed

+71
-48
lines changed

compiler/core/js_dump.ml

Lines changed: 71 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -527,64 +527,19 @@ and expression_desc cxt ~(level : int) f x : cxt =
527527
| Call (e, el, {call_transformed_jsx = Some jsx_element}) -> (
528528
match el with
529529
| [
530-
_tag;
530+
tag;
531531
{
532532
expression_desc =
533533
Caml_block (el, _mutable_flag, _, Lambda.Blk_record {fields});
534534
};
535-
] -> (
535+
] ->
536536
let fields =
537537
Ext_list.array_list_filter_map fields el (fun (f, opt) x ->
538538
match x.expression_desc with
539539
| Undefined _ when opt -> None
540540
| _ -> Some (f, x))
541541
in
542-
match jsx_element with
543-
| Parsetree.Jsx_fragment {jsx_fragment_children = children} ->
544-
P.string f "<>";
545-
(let children =
546-
fields
547-
|> List.find_map (fun (n, e) ->
548-
if n = "children" then Some e else None)
549-
in
550-
children
551-
|> Option.iter (fun c ->
552-
P.string f "{";
553-
let _ = expression ~level:1 cxt f c in
554-
P.string f "}"));
555-
P.string f "</>";
556-
cxt
557-
| Parsetree.Jsx_unary_element
558-
{jsx_unary_element_tag_name = {txt = Longident.Lident tagName}} ->
559-
Printf.eprintf "Crazy Tag: %s\n" tagName;
560-
P.string f (Format.sprintf "<%s />" tagName);
561-
cxt
562-
| Parsetree.Jsx_container_element
563-
{
564-
jsx_container_element_tag_name_start =
565-
{txt = Longident.Lident tagName};
566-
} ->
567-
P.string f (Format.sprintf "<%s" tagName);
568-
List.iter
569-
(fun (n, x) ->
570-
P.space f;
571-
P.string f n;
572-
P.string f "=";
573-
P.string f "{";
574-
let _ = expression ~level:0 cxt f x in
575-
P.string f "}")
576-
fields;
577-
P.string f "></";
578-
P.string f tagName;
579-
P.string f ">";
580-
cxt
581-
| _ ->
582-
expression_desc cxt ~level f
583-
(Call
584-
( e,
585-
el,
586-
{call_transformed_jsx = None; arity = Full; call_info = Call_ml}
587-
)))
542+
print_jsx cxt ~level f tag fields
588543
| _ ->
589544
expression_desc cxt ~level f
590545
(Call
@@ -1027,6 +982,74 @@ and expression_desc cxt ~(level : int) f x : cxt =
1027982
P.string f "...";
1028983
expression ~level:13 cxt f e)
1029984

985+
(*
986+
(* match jsx_element with
987+
| Parsetree.Jsx_fragment {jsx_fragment_children = children} ->
988+
P.string f "<>";
989+
(let children =
990+
fields
991+
|> List.find_map (fun (n, e) ->
992+
if n = "children" then Some e else None)
993+
in
994+
children
995+
|> Option.iter (fun c ->
996+
P.string f "{";
997+
let _ = expression ~level:1 cxt f c in
998+
P.string f "}"));
999+
P.string f "</>";
1000+
cxt
1001+
| Parsetree.Jsx_unary_element
1002+
{jsx_unary_element_tag_name = {txt = Longident.Lident tagName}} ->
1003+
Printf.eprintf "Crazy Tag: %s\n" tagName;
1004+
P.string f (Format.sprintf "<%s />" tagName);
1005+
cxt
1006+
| Parsetree.Jsx_container_element
1007+
{
1008+
jsx_container_element_tag_name_start =
1009+
{txt = Longident.Lident tagName};
1010+
} ->
1011+
P.string f (Format.sprintf "<%s" tagName);
1012+
List.iter
1013+
(fun (n, x) ->
1014+
P.space f;
1015+
P.string f n;
1016+
P.string f "=";
1017+
P.string f "{";
1018+
let _ = expression ~level:0 cxt f x in
1019+
P.string f "}")
1020+
fields;
1021+
P.string f "></";
1022+
P.string f tagName;
1023+
P.string f ">";
1024+
cxt *)
1025+
| _ ->
1026+
expression_desc cxt ~level f
1027+
(Call
1028+
( e,
1029+
el,
1030+
{call_transformed_jsx = None; arity = Full; call_info = Call_ml}
1031+
)))
1032+
*)
1033+
1034+
and print_jsx cxt ~(level : int) f (tag : J.expression)
1035+
(fields : (string * J.expression) list) : cxt =
1036+
ignore (level, tag, fields);
1037+
let children_opt =
1038+
List.find_map (fun (n, e) -> if n = "children" then Some e else None) fields
1039+
in
1040+
(match children_opt with
1041+
| None -> P.string f "< />"
1042+
| Some children ->
1043+
P.string f "<";
1044+
let _ = expression ~level cxt f tag in
1045+
P.string f ">";
1046+
let _ = expression ~level cxt f children in
1047+
P.string f "</";
1048+
let _ = expression ~level cxt f tag in
1049+
P.string f ">");
1050+
1051+
cxt
1052+
10301053
and property_name_and_value_list cxt f (l : J.property_map) =
10311054
iter_lst cxt f l
10321055
(fun cxt f (pn, e) ->

0 commit comments

Comments
 (0)