Skip to content

Commit 0ae9d12

Browse files
authored
Fix inside comment printing for empty dict (#7654)
* Remove trailing comma in empty dict and print inside comment * Remove extra line * Add test * Update CHANGELOG * Don't use List.is_empty
1 parent dbcaa93 commit 0ae9d12

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
- Fix `typeof` parens on functions. https://github.com/rescript-lang/rescript/pull/7643
3737
- Rewatch: Add --dev flag to clean command. https://github.com/rescript-lang/rescript/pull/7622
3838
- Rewatch: Use root package suffix in clean log messages. https://github.com/rescript-lang/rescript/pull/7648
39+
- Fix inside comment printing for empty dict. https://github.com/rescript-lang/rescript/pull/7654
3940

4041
# 12.0.0-beta.1
4142

compiler/syntax/src/res_printer.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ and print_literal_dict_expr ~state (e : Parsetree.expression) cmt_tbl =
15121512
Doc.indent
15131513
(Doc.concat
15141514
[
1515-
Doc.soft_line;
1515+
(if rows = [] then Doc.nil else Doc.soft_line);
15161516
Doc.join
15171517
~sep:(Doc.concat [Doc.text ","; Doc.line])
15181518
(List.map
@@ -1523,8 +1523,8 @@ and print_literal_dict_expr ~state (e : Parsetree.expression) cmt_tbl =
15231523
print_comments doc cmt_tbl e.pexp_loc)
15241524
rows);
15251525
]);
1526-
Doc.trailing_comma;
1527-
Doc.soft_line;
1526+
(if rows = [] then Doc.nil
1527+
else Doc.concat [Doc.trailing_comma; Doc.soft_line]);
15281528
])
15291529

15301530
and print_constructor_declarations ~state ~private_flag
@@ -4225,6 +4225,7 @@ and print_pexp_apply ~state expr cmt_tbl =
42254225
Doc.concat
42264226
[
42274227
Doc.text "dict{";
4228+
print_comments_inside cmt_tbl expr.pexp_loc;
42284229
print_literal_dict_expr ~state key_values cmt_tbl;
42294230
Doc.rbrace;
42304231
]

tests/syntax_tests/data/printer/expr/dict.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// empty dict
22
let x = dict{}
33

4+
// empty dict with inside comment
5+
let x = dict{
6+
// inside comment
7+
8+
}
9+
410
// one value
511
let x = dict{"foo": "bar"}
612

tests/syntax_tests/data/printer/expr/expected/dict.res.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
// empty dict
22
let x = dict{}
33

4+
// empty dict with inside comment
5+
let x = dict{
6+
// inside comment
7+
}
8+
49
// one value
510
let x = dict{"foo": "bar"}
611

0 commit comments

Comments
 (0)