Skip to content

Commit fbf8b11

Browse files
committed
WIP
1 parent 969fed2 commit fbf8b11

File tree

1 file changed

+15
-30
lines changed

1 file changed

+15
-30
lines changed

compiler/syntax/src/res_printer.ml

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,7 +4427,7 @@ and print_jsx_fragment ~state expr cmt_tbl =
44274427
and print_jsx_children ~state (children_expr : Parsetree.expression) ~sep
44284428
cmt_tbl =
44294429
match children_expr.pexp_desc with
4430-
| Pexp_construct ({loc; txt = Longident.Lident "::"}, _) ->
4430+
| Pexp_construct ({txt = Longident.Lident "::"}, _) ->
44314431
let children, _ = ParsetreeViewer.collect_list_expressions children_expr in
44324432
let print_expr (expr : Parsetree.expression) =
44334433
let leading_line_comment_present =
@@ -4448,41 +4448,26 @@ and print_jsx_children ~state (children_expr : Parsetree.expression) ~sep
44484448
| Braced braces_loc ->
44494449
print_comments (add_parens_or_braces expr_doc) cmt_tbl braces_loc
44504450
in
4451+
let get_loc expr =
4452+
match ParsetreeViewer.process_braces_attr expr with
4453+
| None, _ -> expr.pexp_loc
4454+
| Some ({loc}, _), _ -> loc
4455+
in
44514456
let rec loop prev acc exprs =
44524457
match exprs with
44534458
| [] -> List.rev acc
4454-
| ({Parsetree.pexp_loc = current_loc} as expr) :: tails ->
4459+
| expr :: tails ->
4460+
let start_loc = (get_loc expr).loc_start.pos_lnum in
4461+
let end_loc = (get_loc prev).loc_end.pos_lnum in
4462+
let expr_doc = print_expr expr in
44554463
let docs =
4456-
if current_loc.loc_start.pos_lnum - prev.Warnings.loc_end.pos_lnum > 1
4457-
then
4458-
let expr = print_expr expr in
4459-
let acc = Doc.concat [Doc.hard_line; expr] :: acc in
4460-
acc
4461-
else
4462-
let expr = print_expr expr in
4463-
let acc = expr :: acc in
4464-
acc
4465-
in
4466-
(* adjust for braces when we forward the current_loc to the recursion *)
4467-
let current_loc =
4468-
match expr with
4469-
| {Parsetree.pexp_loc = loc}
4470-
when loc.loc_start.pos_lnum == loc.loc_end.pos_lnum ->
4471-
current_loc
4472-
| _ when ParsetreeViewer.is_braced_expr expr ->
4473-
{
4474-
current_loc with
4475-
loc_end =
4476-
{
4477-
current_loc.loc_end with
4478-
pos_lnum = current_loc.loc_end.pos_lnum + 1;
4479-
};
4480-
}
4481-
| _ -> current_loc
4464+
if start_loc - end_loc > 1 then
4465+
Doc.concat [Doc.hard_line; expr_doc] :: acc
4466+
else expr_doc :: acc
44824467
in
4483-
loop current_loc docs tails
4468+
loop expr docs tails
44844469
in
4485-
let docs = loop loc [] children in
4470+
let docs = loop children_expr [] children in
44864471
Doc.group (Doc.join ~sep docs)
44874472
| _ ->
44884473
let leading_line_comment_present =

0 commit comments

Comments
 (0)