Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Pipe reformat eats annotation #629

Merged
merged 5 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lhsDoc;
(match (lhsHasCommentBelow, op) with
| true, "|." -> Doc.concat [Doc.softLine; Doc.text "->"]
Expand Down
8 changes: 8 additions & 0 deletions tests/printer/expr/expected/pipe.res.txt
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions tests/printer/expr/pipe.res
Original file line number Diff line number Diff line change
@@ -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