Skip to content

Commit

Permalink
fix: callback sequences formatted back from .ml (#2799)
Browse files Browse the repository at this point in the history
* fix: callback sequences formatted back from .ml

fixes #2798

* chore: add changelog entry
  • Loading branch information
anmonteiro authored Aug 29, 2024
1 parent 564cc3d commit 6455bb6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
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

0 comments on commit 6455bb6

Please sign in to comment.