diff --git a/CHANGELOG.md b/CHANGELOG.md index 448ff32c..788a99d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ - Initial support for JSX V4, still work in progress. - :boom: when V4 is activated, at most one component is allowed for each module. +#### :bug: Bug Fix + +- Fix issue where the printer would omit attributes for `->` and `|>` https://github.com/rescript-lang/syntax/pull/629 + ## ReScript 10.0 - Fix printing for inline nullary functor types [#477](https://github.com/rescript-lang/syntax/pull/477) diff --git a/src/res_printer.ml b/src/res_printer.ml index c1d947d4..b6f2d9dd 100644 --- a/src/res_printer.ml +++ b/src/res_printer.ml @@ -3651,13 +3651,16 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl = [(Nolabel, lhs); (Nolabel, rhs)] ) when not (ParsetreeViewer.isBinaryExpression lhs - || ParsetreeViewer.isBinaryExpression rhs) -> + || ParsetreeViewer.isBinaryExpression rhs + || printAttributes ~customLayout expr.pexp_attributes cmtTbl + <> Doc.nil) -> let lhsHasCommentBelow = hasCommentBelow cmtTbl lhs.pexp_loc in let lhsDoc = printOperand ~isLhs:true lhs op in let rhsDoc = printOperand ~isLhs:false rhs op in Doc.group (Doc.concat [ + printAttributes ~customLayout expr.pexp_attributes cmtTbl; lhsDoc; (match (lhsHasCommentBelow, op) with | true, "|." -> Doc.concat [Doc.softLine; Doc.text "->"] diff --git a/tests/printer/expr/expected/pipe.res.txt b/tests/printer/expr/expected/pipe.res.txt new file mode 100644 index 00000000..a6ae377f --- /dev/null +++ b/tests/printer/expr/expected/pipe.res.txt @@ -0,0 +1,8 @@ +let s1 = @ann (x->foo) +let s1b = (@ann x)->foo + +let s2 = @ann (x |> foo) +let s2b = (@ann x) |> foo + +let s3 = @ann (x ** foo) +let s3b = (@ann x) ** foo diff --git a/tests/printer/expr/pipe.res b/tests/printer/expr/pipe.res new file mode 100644 index 00000000..82289c87 --- /dev/null +++ b/tests/printer/expr/pipe.res @@ -0,0 +1,8 @@ +let s1 = @ann (x->foo) +let s1b = @ann x->foo + +let s2 = @ann (x|>foo) +let s2b = @ann x|>foo + +let s3 = @ann (x**foo) +let s3b = @ann x**foo