Skip to content

Fix inside comment printing for empty dict #7654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 16, 2025
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- Fix `typeof` parens on functions. https://github.com/rescript-lang/rescript/pull/7643
- Rewatch: Add --dev flag to clean command. https://github.com/rescript-lang/rescript/pull/7622
- Rewatch: Use root package suffix in clean log messages. https://github.com/rescript-lang/rescript/pull/7648
- Fix inside comment printing for empty dict. https://github.com/rescript-lang/rescript/pull/7654

# 12.0.0-beta.1

Expand Down
7 changes: 4 additions & 3 deletions compiler/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ and print_literal_dict_expr ~state (e : Parsetree.expression) cmt_tbl =
Doc.indent
(Doc.concat
[
Doc.soft_line;
(if rows = [] then Doc.nil else Doc.soft_line);
Doc.join
~sep:(Doc.concat [Doc.text ","; Doc.line])
(List.map
Expand All @@ -1523,8 +1523,8 @@ and print_literal_dict_expr ~state (e : Parsetree.expression) cmt_tbl =
print_comments doc cmt_tbl e.pexp_loc)
rows);
]);
Doc.trailing_comma;
Doc.soft_line;
(if rows = [] then Doc.nil
else Doc.concat [Doc.trailing_comma; Doc.soft_line]);
])

and print_constructor_declarations ~state ~private_flag
Expand Down Expand Up @@ -4225,6 +4225,7 @@ and print_pexp_apply ~state expr cmt_tbl =
Doc.concat
[
Doc.text "dict{";
print_comments_inside cmt_tbl expr.pexp_loc;
print_literal_dict_expr ~state key_values cmt_tbl;
Doc.rbrace;
]
Expand Down
6 changes: 6 additions & 0 deletions tests/syntax_tests/data/printer/expr/dict.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// empty dict
let x = dict{}

// empty dict with inside comment
let x = dict{
// inside comment

}

// one value
let x = dict{"foo": "bar"}

Expand Down
5 changes: 5 additions & 0 deletions tests/syntax_tests/data/printer/expr/expected/dict.res.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// empty dict
let x = dict{}

// empty dict with inside comment
let x = dict{
// inside comment
}

// one value
let x = dict{"foo": "bar"}

Expand Down