From f5ca410b05db960cd5e2aae5b5834fdef51b34b3 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Sun, 1 Sep 2024 14:40:17 +0800 Subject: [PATCH] Fix comment removed when function signature has type keyword (#6997) * Fix comment removed when function signature has type keyword * Update CHANGELOG --- CHANGELOG.md | 3 ++- jscomp/syntax/src/res_comments_table.ml | 2 ++ jscomp/syntax/tests/printer/comments/expected/expr.res.txt | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) 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 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 */, ) => ()