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

fix: callback sequences formatted back from .ml #2799

Merged
merged 2 commits into from
Aug 29, 2024
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
[#2794](https://github.com/reasonml/reason/pull/2794))
- Parse universal type variables in signature items (@anmonteiro,
[#2797](https://github.com/reasonml/reason/pull/2797))
- Fix formatting of callbacks with sequence expressions (@anmonteiro,
[#2799](https://github.com/reasonml/reason/pull/2799))

## 3.12.0

Expand Down
10 changes: 7 additions & 3 deletions src/reason-parser/reason_pprint_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9913,9 +9913,13 @@ let createFormatter () =
"=> ", ")" ^ rightWrap
in
let wrap =
if self#should_preserve_requested_braces retCb
then leftWrap ^ "{", "}" ^ rightWrap
else wrap
match
( self#should_preserve_requested_braces retCb
, self#isSeriesOfOpensFollowedByNonSequencyExpression
{ retCb with pexp_attributes = [] } )
with
| true, _ | _, false -> leftWrap ^ "{", "}" ^ rightWrap
| _ -> wrap
in
let right =
source_map
Expand Down
7 changes: 7 additions & 0 deletions test/mlFunctions.t/input.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(* Copyright (c) 2015-present, Facebook, Inc. All rights reserved. *)

let x =
ignore (fun y ->
let y = 4 in
y)

23 changes: 23 additions & 0 deletions test/mlFunctions.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Format basic

$ refmt ./input.ml | tee formatted.re
/* Copyright (c) 2015-present, Facebook, Inc. All rights reserved. */

let x =
ignore(y => {
let y = 4;
y;
});

Format the formatted file back
$ refmt ./formatted.re | tee formatted_back.re
/* Copyright (c) 2015-present, Facebook, Inc. All rights reserved. */

let x =
ignore(y => {
let y = 4;
y;
});

Ensure idempotency: first format and second format are the same
$ diff formatted.re formatted_back.re
Loading