Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve printing of destructuring with local open. #2684

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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 HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 3.9 (unreleased)

- Improve printing of destructuring with local open. [#2684](https://github.com/reasonml/reason/pull/2684)
- Reduce the amount of parentheses around functor usage. [#2683](https://github.com/reasonml/reason/pull/2683)
- Print module type body on separate line (@SanderSpies) [#2709](https://github.com/reasonml/reason/pull/2709)
- Fix missing patterns around contraint pattern (a pattern with a type annotation).
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 @@ -5296,6 +5296,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 "let")
(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
8 changes: 8 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
8 changes: 8 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