@@ -794,17 +794,54 @@ and simple_expr ctxt f x =
794794 let expression = expression ctxt in
795795 pp f fmt (pattern ctxt) s expression e1 direction_flag df expression e2
796796 expression e3
797+ (* TODO: what should this really be?
798+ I miss some context why this print form even exists.
799+ Can/should we improve the output here?
800+ *)
797801 | Pexp_jsx_fragment (_ , xs , _ ) ->
798802 pp f " <>%a</>" (list (simple_expr ctxt)) (collect_jsx_children xs)
799- | Pexp_jsx_unary_element _ -> failwith " TODO: Pexp_jsx_unary_element 2"
800- | Pexp_jsx_container_element _ ->
801- failwith " TODO: Pexp_jsx_container_element 2"
803+ | Pexp_jsx_unary_element
804+ {jsx_unary_element_tag_name = tag_name; jsx_unary_element_props = props}
805+ -> (
806+ let name = Longident. flatten tag_name.txt |> String. concat " ." in
807+ match props with
808+ | [] -> pp f " <%s />" name
809+ | _ -> pp f " <%s %a />" name (print_jsx_props ctxt) props)
810+ | Pexp_jsx_container_element
811+ {
812+ jsx_container_element_tag_name_start = tag_name;
813+ jsx_container_element_props = props;
814+ jsx_container_element_children = children;
815+ } -> (
816+ let name = Longident. flatten tag_name.txt |> String. concat " ." in
817+ match props with
818+ | [] ->
819+ pp f " <%s>%a</%s>" name
820+ (list (simple_expr ctxt))
821+ (collect_jsx_children children)
822+ name
823+ | _ ->
824+ pp f " <%s %a>%a</%s>" name (print_jsx_props ctxt) props
825+ (list (simple_expr ctxt))
826+ (collect_jsx_children children)
827+ name)
802828 | _ -> paren true (expression ctxt) f x
803829
804830and collect_jsx_children = function
805831 | JSXChildrenSpreading e -> [e]
806832 | JSXChildrenItems xs -> xs
807833
834+ and print_jsx_prop ctxt f = function
835+ | JSXPropPunning (is_optional , name ) ->
836+ pp f " %s" (if is_optional then " ?" ^ name.txt else name.txt)
837+ | JSXPropValue (name , is_optional , value ) ->
838+ pp f " %s=%s%a" name.txt
839+ (if is_optional then " ?" else " " )
840+ (simple_expr ctxt) value
841+ | JSXPropSpreading (_ , expr ) -> pp f " {...%a}" (simple_expr ctxt) expr
842+
843+ and print_jsx_props ctxt f = list ~sep: " " (print_jsx_prop ctxt) f
844+
808845and attributes ctxt f l = List. iter (attribute ctxt f) l
809846
810847and item_attributes ctxt f l = List. iter (item_attribute ctxt f) l
0 commit comments