Skip to content

Commit 680d0ad

Browse files
shulhicknitt
authored andcommitted
Fix incorrect format of function under unary operator (#6953)
* Fix parens in unary operator * Fix parens in binary expr * Handle underscore sugar application * Add tests * Update CHANGELOG
1 parent eb00295 commit 680d0ad

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# 11.1.4
1414

1515
- Fix issue where long layout break added a trailing comma in partial application `...`. https://github.com/rescript-lang/rescript-compiler/pull/6949
16+
- Fix incorrect format of function under unary operator. https://github.com/rescript-lang/rescript-compiler/pull/6953
1617

1718
# 11.1.3
1819

jscomp/syntax/src/res_parens.ml

+10
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ let unaryExprOperand expr =
111111
Parenthesized
112112
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes ->
113113
Parenthesized
114+
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some expr)}
115+
when ParsetreeViewer.isUnderscoreApplySugar expr ->
116+
Nothing
117+
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some _)} ->
118+
Parenthesized
114119
| _ -> Nothing)
115120

116121
let binaryExprOperand ~isLhs expr =
@@ -276,6 +281,11 @@ let fieldExpr expr =
276281
Parenthesized
277282
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes ->
278283
Parenthesized
284+
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some expr)}
285+
when ParsetreeViewer.isUnderscoreApplySugar expr ->
286+
Nothing
287+
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some _)} ->
288+
Parenthesized
279289
| _ -> Nothing)
280290

281291
let setFieldExprRhs expr =

jscomp/syntax/tests/printer/expr/expected/unary.res.txt

+2
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,5 @@ let () = {
8585

8686
let x = (!truths)[0]
8787
(!streets)[0] = "foo-street"
88+
89+
!(arg => doStuffWith(arg))

jscomp/syntax/tests/printer/expr/unary.res

+2
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@ let () = {
6868

6969
let x = (!truths)[0]
7070
(!streets)[0] = "foo-street"
71+
72+
!(arg => doStuffWith(arg))

0 commit comments

Comments
 (0)