Skip to content
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

Fix comment removed when function signature has type keyword #6997

Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- Fix incorrect incorrect printing of module binding with signature. https://github.com/rescript-lang/rescript-compiler/pull/6963
- Fix incorrect printing of external with `@as` attribute and `_` placholder (fixed argument). https://github.com/rescript-lang/rescript-compiler/pull/6970
- Disallow spreading anything but regular variants inside of other variants. https://github.com/rescript-lang/rescript-compiler/pull/6980
- Fix comment removed when function signature has `type` keyword. https://github.com/rescript-lang/rescript-compiler/pull/6997

#### :house: Internal

Expand Down Expand Up @@ -2614,4 +2615,4 @@ Features:

# 1.0.0

Initial release
Initial release
2 changes: 2 additions & 0 deletions jscomp/syntax/src/res_comments_table.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,8 @@ and walk_expression expr t comments =
attach t.leading expr.pexp_loc leading;
walk_expression expr t inside;
attach t.trailing expr.pexp_loc trailing
| Pexp_construct ({txt = Longident.Lident "Function$"}, Some return_expr) ->
walk_expression return_expr t comments
| _ ->
if is_block_expr return_expr then walk_expression return_expr t comments
else
Expand Down
4 changes: 2 additions & 2 deletions jscomp/syntax/tests/printer/comments/expected/expr.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ let f = (
/* c6 */ ~x=?,
) => /* c7 */ ()

let multiply = (type /* c-2 */ t /* c-1 */, m1 /* c1 */, /* c2 */ m2 /* c3 */) => ()
let multiply = (type /* c-2 */ t /* c-1 */, /* c0 */ m1 /* c1 */, /* c2 */ m2 /* c3 */) => ()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code actually had the comment, but the expected outcome didn't.

let multiply = (
type /* c-4 */ t /* c-3 */,
m1 /* c1 */,
/* c0 */ m1 /* c1 */,
type /* c-2 */ s /* c-1 */,
/* c2 */ m2 /* c3 */,
) => ()
Expand Down