Skip to content

Commit ce54dfb

Browse files
shulhicknitt
authored andcommitted
Fix parens removed in series of pipes for anonymous uncurried function (rescript-lang#6766)
Handle precedence of uncurried anonymous function in pipe chains. # Conflicts: # CHANGELOG.md
1 parent 517ed77 commit ce54dfb

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
1313
# 11.1.1
1414

15+
#### :bug: Bug Fix
16+
17+
- Fix formatter eats comments on the first argument of a uncurried function. https://github.com/rescript-lang/rescript-compiler/pull/6763
18+
- Fix formatter removes parens in pipe operator with anonymous uncurried function. https://github.com/rescript-lang/rescript-compiler/pull/6766
19+
1520
# 11.1.0
1621

1722
#### :bug: Bug Fix

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)