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

Commit 032bf40

Browse files
authored
441: fix missing comments in switch (#510)
1 parent ce2eb11 commit 032bf40

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/res_printer.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4434,12 +4434,7 @@ and printCases (cases: Parsetree.case list) cmtTbl =
44344434
Doc.concat [
44354435
Doc.line;
44364436
printList
4437-
~getLoc:(fun n -> {n.Parsetree.pc_lhs.ppat_loc with
4438-
loc_end =
4439-
match ParsetreeViewer.processBracesAttr n.Parsetree.pc_rhs with
4440-
| (None, _) -> n.pc_rhs.pexp_loc.loc_end
4441-
| (Some ({loc}, _), _) -> loc.Location.loc_end
4442-
})
4437+
~getLoc:(fun n -> {n.Parsetree.pc_lhs.ppat_loc with loc_end = n.pc_rhs.pexp_loc.loc_end})
44434438
~print:printCase
44444439
~nodes:cases
44454440
cmtTbl

tests/printer/expr/expected/switch.res.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,21 @@ let x =
2222
| Universe => ()
2323
}
2424

25+
// #441 rescript format sometimes deletes comments
2526
switch count {
27+
// String in braces
2628
| 1 => "one"
29+
// Int in braces
30+
| 2 => 2
31+
// Float in braces
32+
| 3 => 3.
33+
// Bool in braces
34+
| 4 => true
35+
// Expression in braces
36+
| 5 => expr
37+
// Block
38+
| 6 => {
39+
let _ = 123
40+
Js.Console.log("Must be block")
41+
}
2742
}

tests/printer/expr/switch.res

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ let x = @attr switch x {
2020
| Universe => ()
2121
}
2222

23+
// #441 rescript format sometimes deletes comments
2324
switch count {
25+
// String in braces
2426
| 1 => { "one" }
27+
// Int in braces
28+
| 2 => {2}
29+
// Float in braces
30+
| 3 => {3.}
31+
// Bool in braces
32+
| 4 => { true }
33+
// Expression in braces
34+
| 5 => { expr }
35+
// Block
36+
| 6 => {
37+
let _ = 123
38+
Js.Console.log("Must be block")
39+
}
2540
}

0 commit comments

Comments
 (0)