diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c4e84f4d6..8ac5645a55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jscomp/syntax/src/res_parens.ml b/jscomp/syntax/src/res_parens.ml index bf946c3159..b100933e86 100644 --- a/jscomp/syntax/src/res_parens.ml +++ b/jscomp/syntax/src/res_parens.ml @@ -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 = @@ -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 = diff --git a/jscomp/syntax/tests/printer/expr/expected/field.res.txt b/jscomp/syntax/tests/printer/expr/expected/field.res.txt index 217b82b11c..f3e2fed896 100644 --- a/jscomp/syntax/tests/printer/expr/expected/field.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/field.res.txt @@ -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 => () diff --git a/jscomp/syntax/tests/printer/expr/expected/unary.res.txt b/jscomp/syntax/tests/printer/expr/expected/unary.res.txt index 62fc8f8075..d1b390b6a2 100644 --- a/jscomp/syntax/tests/printer/expr/expected/unary.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/unary.res.txt @@ -83,3 +83,5 @@ let () = { let x = (!truths)[0] (!streets)[0] = "foo-street" + +!(arg => doStuffWith(arg)) diff --git a/jscomp/syntax/tests/printer/expr/field.res b/jscomp/syntax/tests/printer/expr/field.res index e8a1a62760..f0f48c55f8 100644 --- a/jscomp/syntax/tests/printer/expr/field.res +++ b/jscomp/syntax/tests/printer/expr/field.res @@ -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 => () diff --git a/jscomp/syntax/tests/printer/expr/unary.res b/jscomp/syntax/tests/printer/expr/unary.res index 20f6811655..bfbc90f9f0 100644 --- a/jscomp/syntax/tests/printer/expr/unary.res +++ b/jscomp/syntax/tests/printer/expr/unary.res @@ -66,3 +66,5 @@ let () = { let x = (!truths)[0] (!streets)[0] = "foo-street" + +!(arg => doStuffWith(arg))