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 incorrect format of function under unary operator #6953

Merged
merged 5 commits into from
Aug 16, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

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

# 12.0.0-alpha.1

Expand Down
10 changes: 10 additions & 0 deletions jscomp/syntax/src/res_parens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ let unary_expr_operand expr =
Parenthesized
| _ when ParsetreeViewer.has_await_attribute expr.pexp_attributes ->
Parenthesized
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some expr)}
when ParsetreeViewer.is_underscore_apply_sugar expr ->
Nothing
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some _)} ->
Parenthesized
| _ -> Nothing)

let binary_expr_operand ~is_lhs expr =
Expand Down Expand Up @@ -278,6 +283,11 @@ let field_expr expr =
Parenthesized
| _ when ParsetreeViewer.has_await_attribute expr.pexp_attributes ->
Parenthesized
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some expr)}
when ParsetreeViewer.is_underscore_apply_sugar expr ->
Nothing
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some _)} ->
Parenthesized
| _ -> Nothing)

let set_field_expr_rhs expr =
Expand Down
2 changes: 1 addition & 1 deletion jscomp/syntax/tests/printer/expr/expected/field.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let x = apply(arg1, arg2).field
let x = apply(arg1, arg2).field
let x = (-1).x
let x = (!true).x
//let x = (x => print(x)).x
let x = (x => print(x)).x
let x = (
switch x {
| Blue => ()
Expand Down
2 changes: 2 additions & 0 deletions jscomp/syntax/tests/printer/expr/expected/unary.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ let () = {

let x = (!truths)[0]
(!streets)[0] = "foo-street"

!(arg => doStuffWith(arg))
2 changes: 1 addition & 1 deletion jscomp/syntax/tests/printer/expr/field.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let x = apply(arg1, arg2).field
let x = apply(. arg1, arg2).field
let x = (-1).x
let x = (!true).x
//let x = (x => print(x)).x
let x = (x => print(x)).x
let x = (switch x {
| Blue => ()
| Yello => ()
Expand Down
2 changes: 2 additions & 0 deletions jscomp/syntax/tests/printer/expr/unary.res
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ let () = {

let x = (!truths)[0]
(!streets)[0] = "foo-street"

!(arg => doStuffWith(arg))
Loading