From a79a83eee35d68d10ef7232486eeabe9282f0ee2 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Thu, 23 May 2024 21:24:00 +0800 Subject: [PATCH 1/3] Handle uncurried constr comments --- jscomp/syntax/src/res_comments_table.ml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jscomp/syntax/src/res_comments_table.ml b/jscomp/syntax/src/res_comments_table.ml index 71c2bc95d3..faa521ee58 100644 --- a/jscomp/syntax/src/res_comments_table.ml +++ b/jscomp/syntax/src/res_comments_table.ml @@ -1799,6 +1799,8 @@ and walkCoreType typ t comments = attach t.trailing typexpr.ptyp_loc afterTyp | Ptyp_variant (rowFields, _, _) -> walkList (rowFields |> List.map (fun rf -> RowField rf)) t comments + | Ptyp_constr ({txt = Lident "function$"}, [({ptyp_desc = Ptyp_arrow _}) as desc; _]) -> + walkCoreType desc t comments | Ptyp_constr (longident, typexprs) -> let beforeLongident, _afterLongident = partitionLeadingTrailing comments longident.loc From 55f59b8964cb9f269da6f2470e4b92fefc821b46 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Thu, 23 May 2024 21:30:47 +0800 Subject: [PATCH 2/3] Add test case --- .../printer/comments/expected/typexpr.res.txt | 14 ++++++++++++++ jscomp/syntax/tests/printer/comments/typexpr.res | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/jscomp/syntax/tests/printer/comments/expected/typexpr.res.txt b/jscomp/syntax/tests/printer/comments/expected/typexpr.res.txt index b672ab4da0..5741dde63c 100644 --- a/jscomp/syntax/tests/printer/comments/expected/typexpr.res.txt +++ b/jscomp/syntax/tests/printer/comments/expected/typexpr.res.txt @@ -79,3 +79,17 @@ type jsUser = /* before */ { // above age /* before age */ "age" /* after age */: /* before int */ int /* after int */, } /* after */ + +external test: ( + // comment 1 + ~int: int, + // comment 2 + ~int: int, +) => unit = "test" + +external another_test: ( + // comment 1 + int, + // comment 2 + int, +) => unit = "test" diff --git a/jscomp/syntax/tests/printer/comments/typexpr.res b/jscomp/syntax/tests/printer/comments/typexpr.res index 296ad2ff8b..9cb8c16134 100644 --- a/jscomp/syntax/tests/printer/comments/typexpr.res +++ b/jscomp/syntax/tests/printer/comments/typexpr.res @@ -64,3 +64,17 @@ type jsUser = /* before */ { // above age /* before age */"age" /* after age */: /*before int */ int /*after int */ } /* after */ + +external test: ( + // comment 1 + ~int: int, + // comment 2 + ~int: int, +) => unit = "test" + +external another_test: ( + // comment 1 + int, + // comment 2 + int, +) => unit = "test" From 4287c8b5018a9d88c486fbd97b06179a88b231aa Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Thu, 23 May 2024 21:34:45 +0800 Subject: [PATCH 3/3] Run ocamlformat --- jscomp/syntax/src/res_comments_table.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jscomp/syntax/src/res_comments_table.ml b/jscomp/syntax/src/res_comments_table.ml index faa521ee58..f2153d72b9 100644 --- a/jscomp/syntax/src/res_comments_table.ml +++ b/jscomp/syntax/src/res_comments_table.ml @@ -1799,8 +1799,9 @@ and walkCoreType typ t comments = attach t.trailing typexpr.ptyp_loc afterTyp | Ptyp_variant (rowFields, _, _) -> walkList (rowFields |> List.map (fun rf -> RowField rf)) t comments - | Ptyp_constr ({txt = Lident "function$"}, [({ptyp_desc = Ptyp_arrow _}) as desc; _]) -> - walkCoreType desc t comments + | Ptyp_constr + ({txt = Lident "function$"}, [({ptyp_desc = Ptyp_arrow _} as desc); _]) -> + walkCoreType desc t comments | Ptyp_constr (longident, typexprs) -> let beforeLongident, _afterLongident = partitionLeadingTrailing comments longident.loc