From 555ed362484b1acc3360deaba4b576bbe16faaaf Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Thu, 23 May 2024 22:57:45 +0800 Subject: [PATCH 1/5] Handle proper parens with uncurried anonymous function in pipes --- jscomp/syntax/src/res_parens.ml | 1 + 1 file changed, 1 insertion(+) diff --git a/jscomp/syntax/src/res_parens.ml b/jscomp/syntax/src/res_parens.ml index 5fc2ab9ff8..a24dbb254e 100644 --- a/jscomp/syntax/src/res_parens.ml +++ b/jscomp/syntax/src/res_parens.ml @@ -180,6 +180,7 @@ let flattenOperandRhs parentOperator rhs = let precParent = ParsetreeViewer.operatorPrecedence parentOperator in let precChild = ParsetreeViewer.operatorPrecedence operator in precParent >= precChild || rhs.pexp_attributes <> [] + | Pexp_construct ({ txt = Lident "Function$" }, Some _) -> true | Pexp_constraint ({pexp_desc = Pexp_pack _}, {ptyp_desc = Ptyp_package _}) -> false | Pexp_fun _ when ParsetreeViewer.isUnderscoreApplySugar rhs -> false From eb5bdbd398ff5f2cd14834fa5eca4d99d5590ec7 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Thu, 23 May 2024 23:03:44 +0800 Subject: [PATCH 2/5] Add tests --- .../syntax/tests/printer/expr/expected/smartPipe.res.txt | 8 ++++++++ jscomp/syntax/tests/printer/expr/smartPipe.res | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/jscomp/syntax/tests/printer/expr/expected/smartPipe.res.txt b/jscomp/syntax/tests/printer/expr/expected/smartPipe.res.txt index f67034fc4e..b2641c2fbb 100644 --- a/jscomp/syntax/tests/printer/expr/expected/smartPipe.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/smartPipe.res.txt @@ -31,3 +31,11 @@ let messages = React.useMemo(() => ->Array.filter(ChatMessage.isVisibleInSimpleFilter) ->Array.toSorted(ChatMessage.compareByDateAsc) , [messagesById]) + +f->(v => g(x))->g + +f->(v)->g + +x->(v => g(x))->f->(v => g(x)->k)->g + +f->(v => g(x)->k->(x => s(x)))->g diff --git a/jscomp/syntax/tests/printer/expr/smartPipe.res b/jscomp/syntax/tests/printer/expr/smartPipe.res index 0f1d03531f..2bc8183937 100644 --- a/jscomp/syntax/tests/printer/expr/smartPipe.res +++ b/jscomp/syntax/tests/printer/expr/smartPipe.res @@ -29,3 +29,10 @@ let messages = React.useMemo(() => ->Array.toSorted(ChatMessage.compareByDateAsc) , [messagesById]) +f->(v => g(x))->g + +f->(v)->g + +x->(v => g(x))->f->(v => g(x)->k)->g + +f->(v => g(x)->k->(x => s(x)))->g From 87b7bfaf08ebb7352d7e7e0c28f7ad2fd66c89f1 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Thu, 23 May 2024 23:08:23 +0800 Subject: [PATCH 3/5] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2b0737621..c87dbcc694 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,8 @@ - Fix indent in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6747 - In generated code, use `let` instead of `var`. https://github.com/rescript-lang/rescript-compiler/pull/6102 - Turn off transformation for closures inside loops when capturing loop variables, now that `let` is emitted instead of `var`. https://github.com/rescript-lang/rescript-compiler/pull/6480 +- Fix formatter eats comments on the first argument of a uncurried function. https://github.com/rescript-lang/rescript-compiler/pull/6763 +- Fix formatter removes parens in pipe operator with anonymous uncurried function. https://github.com/rescript-lang/rescript-compiler/pull/6766 # 11.1.0 From 757259c6ed2cb145be4f1ed830ea9a52a1b55ecc Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Fri, 24 May 2024 15:06:23 +0800 Subject: [PATCH 4/5] Fix test output --- jscomp/syntax/tests/printer/expr/expected/smartPipe.res.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jscomp/syntax/tests/printer/expr/expected/smartPipe.res.txt b/jscomp/syntax/tests/printer/expr/expected/smartPipe.res.txt index b2641c2fbb..90b24b0144 100644 --- a/jscomp/syntax/tests/printer/expr/expected/smartPipe.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/smartPipe.res.txt @@ -34,7 +34,7 @@ let messages = React.useMemo(() => f->(v => g(x))->g -f->(v)->g +f->v->g x->(v => g(x))->f->(v => g(x)->k)->g From b691f9b3d3c89950f6999f9eb2cafcb50a10507d Mon Sep 17 00:00:00 2001 From: Shulhi Sapli Date: Fri, 24 May 2024 17:11:08 +0800 Subject: [PATCH 5/5] Fix formatting --- jscomp/syntax/src/res_parens.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jscomp/syntax/src/res_parens.ml b/jscomp/syntax/src/res_parens.ml index a24dbb254e..4c699c9a31 100644 --- a/jscomp/syntax/src/res_parens.ml +++ b/jscomp/syntax/src/res_parens.ml @@ -180,7 +180,7 @@ let flattenOperandRhs parentOperator rhs = let precParent = ParsetreeViewer.operatorPrecedence parentOperator in let precChild = ParsetreeViewer.operatorPrecedence operator in precParent >= precChild || rhs.pexp_attributes <> [] - | Pexp_construct ({ txt = Lident "Function$" }, Some _) -> true + | Pexp_construct ({txt = Lident "Function$"}, Some _) -> true | Pexp_constraint ({pexp_desc = Pexp_pack _}, {ptyp_desc = Ptyp_package _}) -> false | Pexp_fun _ when ParsetreeViewer.isUnderscoreApplySugar rhs -> false