Skip to content

Commit 7f35404

Browse files
committed
WIP
1 parent 64a29eb commit 7f35404

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

compiler/syntax/src/res_printer.ml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4584,6 +4584,18 @@ and get_line_sep_for_jsx_children (children : Parsetree.jsx_children) =
45844584

45854585
and print_jsx_children ~state (children : Parsetree.jsx_children) cmt_tbl =
45864586
let open Parsetree in
4587+
let get_loc (expr : Parsetree.expression) =
4588+
let braces =
4589+
expr.pexp_attributes
4590+
|> List.find_map (fun (attr, _) ->
4591+
match attr with
4592+
| {Location.txt = "res.braces"; loc} -> Some loc
4593+
| _ -> None)
4594+
in
4595+
match braces with
4596+
| None -> expr.pexp_loc
4597+
| Some loc -> loc
4598+
in
45874599
let sep = get_line_sep_for_jsx_children children in
45884600
let print_expr (expr : Parsetree.expression) =
45894601
let leading_line_comment_present =
@@ -4599,7 +4611,7 @@ and print_jsx_children ~state (children : Parsetree.jsx_children) cmt_tbl =
45994611
else Doc.concat [Doc.lbrace; inner_doc; Doc.rbrace]
46004612
in
46014613
match Parens.jsx_child_expr expr with
4602-
| Nothing -> expr_doc
4614+
| Nothing -> print_comments expr_doc cmt_tbl (get_loc expr)
46034615
| Parenthesized -> add_parens_or_braces expr_doc
46044616
| Braced braces_loc ->
46054617
print_comments (add_parens_or_braces expr_doc) cmt_tbl braces_loc
@@ -4608,19 +4620,6 @@ and print_jsx_children ~state (children : Parsetree.jsx_children) cmt_tbl =
46084620
| JSXChildrenItems [] -> Doc.nil
46094621
| JSXChildrenSpreading child -> Doc.concat [Doc.dotdotdot; print_expr child]
46104622
| JSXChildrenItems children ->
4611-
let get_loc (expr : Parsetree.expression) =
4612-
let braces =
4613-
expr.pexp_attributes
4614-
|> List.find_map (fun (attr, _) ->
4615-
match attr with
4616-
| {Location.txt = "res.braces"; loc} -> Some loc
4617-
| _ -> None)
4618-
in
4619-
match braces with
4620-
| None -> expr.pexp_loc
4621-
| Some loc -> loc
4622-
in
4623-
46244623
let rec visit acc children =
46254624
match children with
46264625
| [] -> acc

0 commit comments

Comments
 (0)