@@ -4427,35 +4427,46 @@ and print_jsx_fragment ~state expr cmt_tbl =
44274427and print_jsx_children ~state (children_expr : Parsetree.expression ) ~sep
44284428 cmt_tbl =
44294429 match children_expr.pexp_desc with
4430- | Pexp_construct ({txt = Longident. Lident "::" } , _ ) ->
4430+ | Pexp_construct ({loc; txt = Longident. Lident "::" } , _ ) ->
44314431 let children, _ = ParsetreeViewer. collect_list_expressions children_expr in
4432- Doc. group
4433- (Doc. join ~sep
4434- (List. map
4435- (fun (expr : Parsetree.expression ) ->
4436- let leading_line_comment_present =
4437- has_leading_line_comment cmt_tbl expr.pexp_loc
4438- in
4439- let expr_doc =
4440- print_expression_with_comments ~state expr cmt_tbl
4441- in
4442- let add_parens_or_braces expr_doc =
4443- (* {(20: int)} make sure that we also protect the expression inside *)
4444- let inner_doc =
4445- if Parens. braced_expr expr then add_parens expr_doc
4446- else expr_doc
4447- in
4448- if leading_line_comment_present then add_braces inner_doc
4449- else Doc. concat [Doc. lbrace; inner_doc; Doc. rbrace]
4450- in
4451- match Parens. jsx_child_expr expr with
4452- | Nothing -> expr_doc
4453- | Parenthesized -> add_parens_or_braces expr_doc
4454- | Braced braces_loc ->
4455- print_comments
4456- (add_parens_or_braces expr_doc)
4457- cmt_tbl braces_loc)
4458- children))
4432+ let print_expr (expr : Parsetree.expression ) =
4433+ let leading_line_comment_present =
4434+ has_leading_line_comment cmt_tbl expr.pexp_loc
4435+ in
4436+ let expr_doc = print_expression_with_comments ~state expr cmt_tbl in
4437+ let add_parens_or_braces expr_doc =
4438+ (* {(20: int)} make sure that we also protect the expression inside *)
4439+ let inner_doc =
4440+ if Parens. braced_expr expr then add_parens expr_doc else expr_doc
4441+ in
4442+ if leading_line_comment_present then add_braces inner_doc
4443+ else Doc. concat [Doc. lbrace; inner_doc; Doc. rbrace]
4444+ in
4445+ match Parens. jsx_child_expr expr with
4446+ | Nothing -> expr_doc
4447+ | Parenthesized -> add_parens_or_braces expr_doc
4448+ | Braced braces_loc ->
4449+ print_comments (add_parens_or_braces expr_doc) cmt_tbl braces_loc
4450+ in
4451+ let rec loop prev acc exprs =
4452+ match exprs with
4453+ | [] -> List. rev acc
4454+ | ({Parsetree. pexp_loc = current_loc } as expr ) :: tails ->
4455+ 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+ loop current_loc docs tails
4467+ in
4468+ let docs = loop loc [] children in
4469+ Doc. group (Doc. join ~sep docs)
44594470 | _ ->
44604471 let leading_line_comment_present =
44614472 has_leading_line_comment cmt_tbl children_expr.pexp_loc
0 commit comments