Skip to content

Commit

Permalink
improve printing of arrows with labelled arguments (#2778)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Jul 29, 2024
1 parent b681d24 commit 4b74bb1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
7 changes: 5 additions & 2 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2512,9 +2512,12 @@ let printer = object(self:'self)
let t = match lbl with
| Nolabel -> typ
| Labelled lbl ->
makeList ~sep:(Sep " ") [atom (namedArgSym ^ lbl ^ ":"); typ]
label ~space:true (atom (namedArgSym ^ lbl ^ ":")) typ
| Optional lbl ->
makeList ~sep:(Sep " ") [atom (namedArgSym ^ lbl ^ ":"); label typ (atom "=?")]
label
~space:true
(atom (namedArgSym ^ lbl ^ ":"))
(label typ (atom "=?"))
in
if uncurried then
makeList ~postSpace:true [atom "."; t]
Expand Down
13 changes: 6 additions & 7 deletions test/general-syntax-re.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ Format general implementation syntax
list(int);
type firstTwoShouldBeGroupedAndFirstThree =
(
~first: (list(int) => list(int)) =>
list(int)
~first:
(list(int) => list(int)) => list(int)
) =>
list(int);

Expand Down Expand Up @@ -840,17 +840,16 @@ Format general implementation syntax

type typeWithNestedNamedArgs =
(
~outerOne: (~innerOne: int, ~innerTwo: int) =>
int,
~outerOne:
(~innerOne: int, ~innerTwo: int) => int,
~outerTwo: int
) =>
int;

type typeWithNestedOptionalNamedArgs =
(
~outerOne: (~innerOne: int, ~innerTwo: int) =>
int
=?,
~outerOne:
(~innerOne: int, ~innerTwo: int) => int=?,
~outerTwo: int=?
) =>
int;
Expand Down
12 changes: 12 additions & 0 deletions test/general-syntax-rei.t/input.rei
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,15 @@ module%foo X = Y;

module%foo rec X: Y;

let wrapReasonForJs:
(
~component: componentSpec(
'state,
'initialState,
'retainedProps,
'initialRetainedPropssssssssssssssssss,
'action
)
) =>
reactClass;

13 changes: 13 additions & 0 deletions test/general-syntax-rei.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,16 @@ Format general interface syntax
module%foo X = Y;

module%foo rec X: Y;

let wrapReasonForJs:
(
~component:
componentSpec(
'state,
'initialState,
'retainedProps,
'initialRetainedPropssssssssssssssssss,
'action,
)
) =>
reactClass;

0 comments on commit 4b74bb1

Please sign in to comment.