@@ -4583,18 +4583,31 @@ and get_line_sep_for_jsx_children (children : Parsetree.jsx_children) =
4583
4583
4584
4584
and print_jsx_children ~state (children : Parsetree.jsx_children ) cmt_tbl =
4585
4585
let open Parsetree in
4586
+ let get_loc (expr : Parsetree.expression ) =
4587
+ let braces =
4588
+ expr.pexp_attributes
4589
+ |> List. find_map (fun (attr , _ ) ->
4590
+ match attr with
4591
+ | {Location. txt = "res.braces" ; loc} -> Some loc
4592
+ | _ -> None )
4593
+ in
4594
+ match braces with
4595
+ | None -> expr.pexp_loc
4596
+ | Some loc -> loc
4597
+ in
4586
4598
let sep = get_line_sep_for_jsx_children children in
4587
4599
let print_expr (expr : Parsetree.expression ) =
4588
4600
let leading_line_comment_present =
4589
- has_leading_line_comment cmt_tbl expr.pexp_loc
4601
+ has_leading_line_comment cmt_tbl (get_loc expr)
4590
4602
in
4591
4603
let expr_doc = print_expression_with_comments ~state expr cmt_tbl in
4592
4604
let add_parens_or_braces expr_doc =
4593
4605
(* {(20: int)} make sure that we also protect the expression inside *)
4594
4606
let inner_doc =
4595
4607
if Parens. braced_expr expr then add_parens expr_doc else expr_doc
4596
4608
in
4597
- if leading_line_comment_present then add_braces inner_doc
4609
+ if leading_line_comment_present then
4610
+ print_comments inner_doc cmt_tbl (get_loc expr)
4598
4611
else Doc. concat [Doc. lbrace; inner_doc; Doc. rbrace]
4599
4612
in
4600
4613
match Parens. jsx_child_expr expr with
@@ -4607,19 +4620,6 @@ and print_jsx_children ~state (children : Parsetree.jsx_children) cmt_tbl =
4607
4620
| JSXChildrenItems [] -> Doc. nil
4608
4621
| JSXChildrenSpreading child -> Doc. concat [Doc. dotdotdot; print_expr child]
4609
4622
| JSXChildrenItems children ->
4610
- let get_loc (expr : Parsetree.expression ) =
4611
- let braces =
4612
- expr.pexp_attributes
4613
- |> List. find_map (fun (attr , _ ) ->
4614
- match attr with
4615
- | {Location. txt = "res.braces" ; loc} -> Some loc
4616
- | _ -> None )
4617
- in
4618
- match braces with
4619
- | None -> expr.pexp_loc
4620
- | Some loc -> loc
4621
- in
4622
-
4623
4623
let rec visit acc children =
4624
4624
match children with
4625
4625
| [] -> acc
0 commit comments