Skip to content

Commit a1cad21

Browse files
authored
Fix parens removed in series of pipes for anonymous uncurried function (#6766)
Handle precedence of uncurried anonymous function in pipe chains.
1 parent 7324f38 commit a1cad21

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
- Fix indent in generated js code. https://github.com/rescript-lang/rescript-compiler/pull/6747
3939
- In generated code, use `let` instead of `var`. https://github.com/rescript-lang/rescript-compiler/pull/6102
4040
- 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
41+
- Fix formatter eats comments on the first argument of a uncurried function. https://github.com/rescript-lang/rescript-compiler/pull/6763
42+
- Fix formatter removes parens in pipe operator with anonymous uncurried function. https://github.com/rescript-lang/rescript-compiler/pull/6766
4143

4244
# 11.1.0
4345

jscomp/syntax/src/res_parens.ml

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ let flattenOperandRhs parentOperator rhs =
180180
let precParent = ParsetreeViewer.operatorPrecedence parentOperator in
181181
let precChild = ParsetreeViewer.operatorPrecedence operator in
182182
precParent >= precChild || rhs.pexp_attributes <> []
183+
| Pexp_construct ({txt = Lident "Function$"}, Some _) -> true
183184
| Pexp_constraint ({pexp_desc = Pexp_pack _}, {ptyp_desc = Ptyp_package _}) ->
184185
false
185186
| Pexp_fun _ when ParsetreeViewer.isUnderscoreApplySugar rhs -> false

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

+8
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,11 @@ let messages = React.useMemo(() =>
3131
->Array.filter(ChatMessage.isVisibleInSimpleFilter)
3232
->Array.toSorted(ChatMessage.compareByDateAsc)
3333
, [messagesById])
34+
35+
f->(v => g(x))->g
36+
37+
f->v->g
38+
39+
x->(v => g(x))->f->(v => g(x)->k)->g
40+
41+
f->(v => g(x)->k->(x => s(x)))->g

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

+7
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ let messages = React.useMemo(() =>
2929
->Array.toSorted(ChatMessage.compareByDateAsc)
3030
, [messagesById])
3131

32+
f->(v => g(x))->g
33+
34+
f->(v)->g
35+
36+
x->(v => g(x))->f->(v => g(x)->k)->g
37+
38+
f->(v => g(x)->k->(x => s(x)))->g

0 commit comments

Comments
 (0)