Skip to content

Commit 4a1fbf3

Browse files
authored
Fix incorrect format of function under unary operator (rescript-lang#6953)
* Fix parens in unary operator * Fix parens in binary expr * Handle underscore sugar application * Add tests * Update CHANGELOG
1 parent 29e3d07 commit 4a1fbf3

File tree

6 files changed

+17
-2
lines changed

6 files changed

+17
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#### :bug: Bug Fix
2727
- Fix issue where long layout break added a trailing comma in partial application `...`. https://github.com/rescript-lang/rescript-compiler/pull/6949
28+
- Fix incorrect format of function under unary operator. https://github.com/rescript-lang/rescript-compiler/pull/6953
2829

2930
# 12.0.0-alpha.1
3031

jscomp/syntax/src/res_parens.ml

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

116121
let binary_expr_operand ~is_lhs expr =
@@ -278,6 +283,11 @@ let field_expr expr =
278283
Parenthesized
279284
| _ when ParsetreeViewer.has_await_attribute expr.pexp_attributes ->
280285
Parenthesized
286+
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some expr)}
287+
when ParsetreeViewer.is_underscore_apply_sugar expr ->
288+
Nothing
289+
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some _)} ->
290+
Parenthesized
281291
| _ -> Nothing)
282292

283293
let set_field_expr_rhs expr =

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let x = apply(arg1, arg2).field
2020
let x = apply(arg1, arg2).field
2121
let x = (-1).x
2222
let x = (!true).x
23-
//let x = (x => print(x)).x
23+
let x = (x => print(x)).x
2424
let x = (
2525
switch x {
2626
| Blue => ()

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

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

8484
let x = (!truths)[0]
8585
(!streets)[0] = "foo-street"
86+
87+
!(arg => doStuffWith(arg))

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let x = apply(arg1, arg2).field
2121
let x = apply(. arg1, arg2).field
2222
let x = (-1).x
2323
let x = (!true).x
24-
//let x = (x => print(x)).x
24+
let x = (x => print(x)).x
2525
let x = (switch x {
2626
| Blue => ()
2727
| Yello => ()

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

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

6767
let x = (!truths)[0]
6868
(!streets)[0] = "foo-street"
69+
70+
!(arg => doStuffWith(arg))

0 commit comments

Comments
 (0)