From 3c20258a430fa00ec2d728571c24f511bc58054c Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 29 May 2022 14:18:21 +0200 Subject: [PATCH] 441: fix missing comments in switch --- src/res_printer.ml | 7 +------ tests/printer/expr/expected/switch.res.txt | 15 +++++++++++++++ tests/printer/expr/switch.res | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/res_printer.ml b/src/res_printer.ml index 9df57ba8..f67fe12f 100644 --- a/src/res_printer.ml +++ b/src/res_printer.ml @@ -4434,12 +4434,7 @@ and printCases (cases: Parsetree.case list) cmtTbl = Doc.concat [ Doc.line; printList - ~getLoc:(fun n -> {n.Parsetree.pc_lhs.ppat_loc with - loc_end = - match ParsetreeViewer.processBracesAttr n.Parsetree.pc_rhs with - | (None, _) -> n.pc_rhs.pexp_loc.loc_end - | (Some ({loc}, _), _) -> loc.Location.loc_end - }) + ~getLoc:(fun n -> {n.Parsetree.pc_lhs.ppat_loc with loc_end = n.pc_rhs.pexp_loc.loc_end}) ~print:printCase ~nodes:cases cmtTbl diff --git a/tests/printer/expr/expected/switch.res.txt b/tests/printer/expr/expected/switch.res.txt index 2edee31c..1cff8ed4 100644 --- a/tests/printer/expr/expected/switch.res.txt +++ b/tests/printer/expr/expected/switch.res.txt @@ -22,6 +22,21 @@ let x = | Universe => () } +// #441 rescript format sometimes deletes comments switch count { +// String in braces | 1 => "one" +// Int in braces +| 2 => 2 +// Float in braces +| 3 => 3. +// Bool in braces +| 4 => true +// Expression in braces +| 5 => expr +// Block +| 6 => { + let _ = 123 + Js.Console.log("Must be block") + } } diff --git a/tests/printer/expr/switch.res b/tests/printer/expr/switch.res index 51607389..615925ce 100644 --- a/tests/printer/expr/switch.res +++ b/tests/printer/expr/switch.res @@ -20,6 +20,21 @@ let x = @attr switch x { | Universe => () } +// #441 rescript format sometimes deletes comments switch count { +// String in braces | 1 => { "one" } +// Int in braces +| 2 => {2} +// Float in braces +| 3 => {3.} +// Bool in braces +| 4 => { true } +// Expression in braces +| 5 => { expr } +// Block +| 6 => { + let _ = 123 + Js.Console.log("Must be block") + } }