Skip to content

Commit 93c6bfa

Browse files
shulhicknitt
andauthored
Fix superfluous parens for underscore application (#7370)
* Fix superfluous parens for underscore application * Update CHANGELOG --------- Co-authored-by: Christoph Knittel <[email protected]>
1 parent 1ad3d50 commit 93c6bfa

File tree

5 files changed

+17
-5
lines changed

5 files changed

+17
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
- Fix `Error.fromException`. https://github.com/rescript-lang/rescript/pull/7364
1818
- Fix signature of `throw`. https://github.com/rescript-lang/rescript/pull/7365
19+
- Fix formatter adds superfluous parens in pipe chain. https://github.com/rescript-lang/rescript/pull/7370
1920

2021
#### :house: Internal
2122

compiler/syntax/src/res_parens.ml

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ let flatten_operand_rhs parent_operator rhs =
185185
prec_parent >= prec_child || rhs.pexp_attributes <> []
186186
| Pexp_constraint ({pexp_desc = Pexp_pack _}, {ptyp_desc = Ptyp_package _}) ->
187187
false
188+
| Pexp_fun {lhs = {ppat_desc = Ppat_var {txt = "__x"}}} -> false
188189
| Pexp_fun _ | Pexp_newtype _ | Pexp_setfield _ | Pexp_constraint _ -> true
189190
| _ when ParsetreeViewer.is_ternary_expr rhs -> true
190191
| _ -> false

tests/syntax_tests/data/printer/expr/expected/callback.res.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,14 @@ let f = () => {
218218
}
219219

220220
myPromise
221-
->(Js.Promise.then_(value => {
221+
->Js.Promise.then_(value => {
222222
Js.log(value)
223223
Js.Promise.resolve(value + 2)
224-
}, _))
225-
->(Js.Promise.then_(value => {
224+
}, _)
225+
->Js.Promise.then_(value => {
226226
Js.log(value)
227227
Js.Promise.resolve(value + 3)
228-
}, _))
228+
}, _)
229229
->Js.Promise.catch(err => {
230230
Js.log2("Failure!!", err)
231231
Js.Promise.resolve(-2)

tests/syntax_tests/data/printer/expr/expected/underscoreApply.res.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ f((a, b) => List.length(_), a, b)
3636
f(a, b, _)(x, y)
3737
-f(a, b, _)
3838
f(a, b, _) + g(x, _, z)
39-
f(a, b, _) + (g(x, _, z)) + h(alpha, beta, _)
39+
f(a, b, _) + g(x, _, z) + h(alpha, beta, _)
4040

4141
assert(f(a, b, _))
4242

@@ -66,3 +66,8 @@ x => {
6666
// Comment 2
6767
something()
6868
}, _)
69+
70+
let status =
71+
json
72+
->optional(field("status", string, _), _)
73+
->Option.mapOr(Status.Active, Status.fromString)

tests/syntax_tests/data/printer/expr/underscoreApply.res

+5
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,8 @@ underscoreWithComments(
7171
},
7272
_,
7373
)
74+
75+
let status =
76+
json
77+
->optional(field("status", string, _), _)
78+
->Option.mapOr(Status.Active, Status.fromString)

0 commit comments

Comments
 (0)