Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

441: fix missing comments in switch #510

Merged
merged 1 commit into from
May 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/printer/expr/expected/switch.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
15 changes: 15 additions & 0 deletions tests/printer/expr/switch.res
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}