From db0f66f12f7bef8a176551a010aca52932a6a48f Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Sun, 1 Sep 2024 11:34:10 +0800 Subject: [PATCH 1/2] Fix comment removed when function signature has type keyword --- jscomp/syntax/src/res_comments_table.ml | 2 ++ jscomp/syntax/tests/printer/comments/expected/expr.res.txt | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/jscomp/syntax/src/res_comments_table.ml b/jscomp/syntax/src/res_comments_table.ml index 14365c77b3..b992aed18e 100644 --- a/jscomp/syntax/src/res_comments_table.ml +++ b/jscomp/syntax/src/res_comments_table.ml @@ -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 diff --git a/jscomp/syntax/tests/printer/comments/expected/expr.res.txt b/jscomp/syntax/tests/printer/comments/expected/expr.res.txt index cd3d56bfa6..8fc8f09702 100644 --- a/jscomp/syntax/tests/printer/comments/expected/expr.res.txt +++ b/jscomp/syntax/tests/printer/comments/expected/expr.res.txt @@ -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 */) => () let multiply = ( type /* c-4 */ t /* c-3 */, - m1 /* c1 */, + /* c0 */ m1 /* c1 */, type /* c-2 */ s /* c-1 */, /* c2 */ m2 /* c3 */, ) => () From 2cf9867e08ef5922653ed5284934d668ea882f5a Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Sun, 1 Sep 2024 11:36:18 +0800 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4869e7e8eb..4787fec7d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -2614,4 +2615,4 @@ Features: # 1.0.0 -Initial release \ No newline at end of file +Initial release