diff --git a/CHANGELOG.md b/CHANGELOG.md index e1a901c3..4abc98cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ - Fix support for recursive components in JSX V4 https://github.com/rescript-lang/syntax/pull/733 - Fix issue with overlapping labelled argument with default value https://github.com/rescript-lang/syntax/pull/734 - Fix issue with using alias and default value together https://github.com/rescript-lang/syntax/pull/734 +- Fix formatting of `switch` expressions that contain braced `cases` inside https://github.com/rescript-lang/syntax/pull/735 #### :eyeglasses: Spec Compliance diff --git a/src/res_comments_table.ml b/src/res_comments_table.ml index 3078505b..889c3811 100644 --- a/src/res_comments_table.ml +++ b/src/res_comments_table.ml @@ -345,7 +345,13 @@ let getLoc node = let open Parsetree in match node with | Case case -> - {case.pc_lhs.ppat_loc with loc_end = case.pc_rhs.pexp_loc.loc_end} + { + case.pc_lhs.ppat_loc with + loc_end = + (match ParsetreeViewer.processBracesAttr case.pc_rhs with + | None, _ -> case.pc_rhs.pexp_loc.loc_end + | Some ({loc}, _), _ -> loc.Location.loc_end); + } | CoreType ct -> ct.ptyp_loc | ExprArgument expr -> ( match expr.Parsetree.pexp_attributes with diff --git a/src/res_printer.ml b/src/res_printer.ml index 3dcd1034..f63bfa77 100644 --- a/src/res_printer.ml +++ b/src/res_printer.ml @@ -4743,7 +4743,10 @@ and printCases ~customLayout (cases : Parsetree.case list) cmtTbl = ~getLoc:(fun n -> { n.Parsetree.pc_lhs.ppat_loc with - loc_end = n.pc_rhs.pexp_loc.loc_end; + loc_end = + (match ParsetreeViewer.processBracesAttr n.pc_rhs with + | None, _ -> n.pc_rhs.pexp_loc.loc_end + | Some ({loc}, _), _ -> loc.Location.loc_end); }) ~print:(printCase ~customLayout) ~nodes:cases cmtTbl; ]; diff --git a/tests/printer/expr/expected/switch.res.txt b/tests/printer/expr/expected/switch.res.txt index 852c64b3..da576e4d 100644 --- a/tests/printer/expr/expected/switch.res.txt +++ b/tests/printer/expr/expected/switch.res.txt @@ -55,3 +55,11 @@ switch route {