Skip to content

Commit e4bda3b

Browse files
committed
Fix some jsx printing
1 parent 0301a06 commit e4bda3b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

compiler/syntax/src/res_printer.ml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4514,7 +4514,26 @@ and print_jsx_children ~state (children_expr : Parsetree.expression) ~sep
45144514
in
45154515
let docs = loop children_expr [] children in
45164516
Doc.group (Doc.join ~sep docs)
4517-
| _ -> print_jsx_child ~state children_expr cmt_tbl
4517+
| _ ->
4518+
let leading_line_comment_present =
4519+
has_leading_line_comment cmt_tbl children_expr.pexp_loc
4520+
in
4521+
let expr_doc =
4522+
print_expression_with_comments ~state children_expr cmt_tbl
4523+
in
4524+
Doc.concat
4525+
[
4526+
Doc.dotdotdot;
4527+
(match Parens.jsx_child_expr children_expr with
4528+
| Parenthesized | Braced _ ->
4529+
let inner_doc =
4530+
if Parens.braced_expr children_expr then add_parens expr_doc
4531+
else expr_doc
4532+
in
4533+
if leading_line_comment_present then add_braces inner_doc
4534+
else Doc.concat [Doc.lbrace; inner_doc; Doc.rbrace]
4535+
| Nothing -> expr_doc);
4536+
]
45184537

45194538
and print_jsx_props ~state args cmt_tbl : Doc.t * Parsetree.expression option =
45204539
(* This function was introduced because we have different formatting behavior for self-closing tags and other tags

0 commit comments

Comments
 (0)