@@ -2394,7 +2394,7 @@ and print_value_binding ~state ~rec_flag (vb : Parsetree.value_binding) cmt_tbl
23942394 print_typ_expr ~state pvc_type cmt_tbl;
23952395 Doc. text " =" ;
23962396 Doc. line;
2397- print_expression_with_comments ~state expr cmt_tbl;
2397+ print_expression_with_comments_and_parens ~state expr cmt_tbl;
23982398 ]);
23992399 ])
24002400 | {
@@ -2438,7 +2438,8 @@ and print_value_binding ~state ~rec_flag (vb : Parsetree.value_binding) cmt_tbl
24382438 Doc. concat
24392439 [
24402440 Doc. line;
2441- print_expression_with_comments ~state expr cmt_tbl;
2441+ print_expression_with_comments_and_parens ~state expr
2442+ cmt_tbl;
24422443 ];
24432444 ]);
24442445 ])
@@ -2465,7 +2466,8 @@ and print_value_binding ~state ~rec_flag (vb : Parsetree.value_binding) cmt_tbl
24652466 Doc. concat
24662467 [
24672468 Doc. line;
2468- print_expression_with_comments ~state expr cmt_tbl;
2469+ print_expression_with_comments_and_parens ~state expr
2470+ cmt_tbl;
24692471 ];
24702472 ]);
24712473 ]))
@@ -3060,6 +3062,13 @@ and print_expression_with_comments ~state expr cmt_tbl : Doc.t =
30603062 let doc = print_expression ~state expr cmt_tbl in
30613063 print_comments doc cmt_tbl expr.Parsetree. pexp_loc
30623064
3065+ and print_expression_with_comments_and_parens ~state expr cmt_tbl =
3066+ let doc = print_expression_with_comments ~state expr cmt_tbl in
3067+ match Parens. expr expr with
3068+ | Parens. Parenthesized -> add_parens doc
3069+ | Braced braces -> print_braces doc expr braces
3070+ | Nothing -> doc
3071+
30633072and print_if_chain ~state pexp_attributes ifs else_expr cmt_tbl =
30643073 let if_docs =
30653074 Doc. join ~sep: Doc. space
@@ -5014,7 +5023,7 @@ and print_jsx_prop ~state prop cmt_tbl =
50145023 [
50155024 Doc. lbrace;
50165025 Doc. dotdotdot;
5017- print_expression_with_comments ~state value cmt_tbl;
5026+ print_expression_with_comments_and_parens ~state value cmt_tbl;
50185027 Doc. rbrace;
50195028 ])
50205029 in
@@ -5418,7 +5427,7 @@ and print_case ~state (case : Parsetree.case) cmt_tbl =
54185427 [
54195428 Doc. line;
54205429 Doc. text " if " ;
5421- print_expression_with_comments ~state expr cmt_tbl;
5430+ print_expression_with_comments_and_parens ~state expr cmt_tbl;
54225431 ])
54235432 in
54245433 let should_inline_rhs =
@@ -5977,7 +5986,7 @@ and print_payload ~state (payload : Parsetree.payload) cmt_tbl =
59775986 [
59785987 Doc. line;
59795988 Doc. text " if " ;
5980- print_expression_with_comments ~state expr cmt_tbl;
5989+ print_expression_with_comments_and_parens ~state expr cmt_tbl;
59815990 ]
59825991 | None -> Doc. nil
59835992 in
0 commit comments