Skip to content

Commit 8100772

Browse files
authored
Fix formatter eats comments on the first argument of a uncurried function (#6763)
Print comments inside uncurried arrow function types correctly.
1 parent bb7665b commit 8100772

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

jscomp/syntax/src/res_comments_table.ml

+3
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,9 @@ and walkCoreType typ t comments =
17991799
attach t.trailing typexpr.ptyp_loc afterTyp
18001800
| Ptyp_variant (rowFields, _, _) ->
18011801
walkList (rowFields |> List.map (fun rf -> RowField rf)) t comments
1802+
| Ptyp_constr
1803+
({txt = Lident "function$"}, [({ptyp_desc = Ptyp_arrow _} as desc); _]) ->
1804+
walkCoreType desc t comments
18021805
| Ptyp_constr (longident, typexprs) ->
18031806
let beforeLongident, _afterLongident =
18041807
partitionLeadingTrailing comments longident.loc

jscomp/syntax/tests/printer/comments/expected/typexpr.res.txt

+14
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,17 @@ type jsUser = /* before */ {
7979
// above age
8080
/* before age */ "age" /* after age */: /* before int */ int /* after int */,
8181
} /* after */
82+
83+
external test: (
84+
// comment 1
85+
~int: int,
86+
// comment 2
87+
~int: int,
88+
) => unit = "test"
89+
90+
external another_test: (
91+
// comment 1
92+
int,
93+
// comment 2
94+
int,
95+
) => unit = "test"

jscomp/syntax/tests/printer/comments/typexpr.res

+14
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,17 @@ type jsUser = /* before */ {
6464
// above age
6565
/* before age */"age" /* after age */: /*before int */ int /*after int */
6666
} /* after */
67+
68+
external test: (
69+
// comment 1
70+
~int: int,
71+
// comment 2
72+
~int: int,
73+
) => unit = "test"
74+
75+
external another_test: (
76+
// comment 1
77+
int,
78+
// comment 2
79+
int,
80+
) => unit = "test"

0 commit comments

Comments
 (0)