Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
(@anmonteiro, [#2774](https://github.com/reasonml/reason/pull/2774))
- Print poly variants as normal variansts (@Sander Spies) [#2708](https://github.com/reasonml/reason/pull/2708)
- Improve printing of anonymous function return type
- Improve printing of destructuring with local open. [#2684](https://github.com/reasonml/reason/pull/2684)

## 3.12.0

Expand Down
28 changes: 28 additions & 0 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5312,6 +5312,34 @@ let printer = object(self:'self)
forms of explicit polymorphic annotations in the parse tree, and how
we must recover them here.
*)
| [], (Ppat_open (lid, {ppat_desc = Ppat_record(l, closed); _})) ->
(*
Special case handling for:

let Foo.{
destruct1,
destruct2,
destruct3,
destruct4,
destruct5,
} = bar;
*)

let upUntilEqual =
let pat = self#patternRecord l closed in
label
(label ~space:true
(atom prefixText)
(label
(self#longident_loc lid)
(atom ("."))
)
)
pat
in
let appTerms = self#unparseExprApplicationItems expr in
let includingEqual = makeList ~postSpace:true [upUntilEqual; atom "="] in
formatAttachmentApplication applicationFinalWrapping (Some (true, includingEqual)) appTerms
| [], (Ppat_constraint(p, ty)) -> (
(* Locally abstract forall types are *seriously* mangled by the parsing
stage, and we have to be very smart about how to recover it.
Expand Down
15 changes: 15 additions & 0 deletions test/general-syntax-re.t/input.re
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,14 @@ let testCallNamedArgs = (foo: ((~a: int, ~b: int=?) => int), a, b) =>
let Foo.{name} = bar;
let Foo.Bar.{name} = bar;

let Foo.{
destruct1,
destruct2,
destruct3,
destruct4,
destruct5,
} = fooBar;

let Foo.[ name ] = bar;
let Foo.Bar.[ name ] = bar;

Expand Down Expand Up @@ -1284,3 +1292,10 @@ let x = 1.123g;

let x = switch () { | _ => .};

let%foo Foo.{
destruct1,
destruct2,
destruct3,
destruct4,
destruct5,
} = fooBar;
16 changes: 16 additions & 0 deletions test/general-syntax-re.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,14 @@ Format general implementation syntax
let Foo.{name} = bar;
let Foo.Bar.{name} = bar;

let Foo.{
destruct1,
destruct2,
destruct3,
destruct4,
destruct5,
} = fooBar;

let Foo.[name] = bar;
let Foo.Bar.[name] = bar;

Expand Down Expand Up @@ -1472,3 +1480,11 @@ Format general implementation syntax
switch () {
| _ => .
};

let%foo Foo.{
destruct1,
destruct2,
destruct3,
destruct4,
destruct5,
} = fooBar;