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

Merged
merged 8 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Improve printing of destructuring with local open.
  • Loading branch information
SanderSpies committed Feb 24, 2023
commit ab080d3c5f24912ad8f0aafba8f94f31e44bcc8f
8 changes: 8 additions & 0 deletions formatTest/unit_tests/expected_output/syntax.re
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,14 @@ let testCallNamedArgs =
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 formatTest/unit_tests/input/syntax.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
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