Skip to content

Commit b266802

Browse files
committed
WIP
1 parent 6303dc5 commit b266802

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

compiler/syntax/src/res_parens.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,7 @@ let jsx_prop_expr expr =
353353

354354
let jsx_child_expr expr =
355355
match expr.Parsetree.pexp_desc with
356-
| Parsetree.Pexp_let _ | Pexp_sequence _ | Pexp_letexception _
357-
| Pexp_letmodule _ | Pexp_open _ ->
356+
| Pexp_sequence _ | Pexp_letexception _ | Pexp_letmodule _ | Pexp_open _ ->
358357
Nothing
359358
| _ -> (
360359
let opt_braces, _ = ParsetreeViewer.process_braces_attr expr in

compiler/syntax/src/res_printer.ml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4583,18 +4583,31 @@ and get_line_sep_for_jsx_children (children : Parsetree.jsx_children) =
45834583

45844584
and print_jsx_children ~state (children : Parsetree.jsx_children) cmt_tbl =
45854585
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
45864598
let sep = get_line_sep_for_jsx_children children in
45874599
let print_expr (expr : Parsetree.expression) =
45884600
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)
45904602
in
45914603
let expr_doc = print_expression_with_comments ~state expr cmt_tbl in
45924604
let add_parens_or_braces expr_doc =
45934605
(* {(20: int)} make sure that we also protect the expression inside *)
45944606
let inner_doc =
45954607
if Parens.braced_expr expr then add_parens expr_doc else expr_doc
45964608
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)
45984611
else Doc.concat [Doc.lbrace; inner_doc; Doc.rbrace]
45994612
in
46004613
match Parens.jsx_child_expr expr with
@@ -4607,19 +4620,6 @@ and print_jsx_children ~state (children : Parsetree.jsx_children) cmt_tbl =
46074620
| JSXChildrenItems [] -> Doc.nil
46084621
| JSXChildrenSpreading child -> Doc.concat [Doc.dotdotdot; print_expr child]
46094622
| 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-
46234623
let rec visit acc children =
46244624
match children with
46254625
| [] -> acc

0 commit comments

Comments
 (0)