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

Fix issue where printing nested pipe discards await #688

Merged
merged 3 commits into from
Oct 16, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- Fix issue where the formatter would delete `async` in a function with labelled arguments.
- Fix several printing issues with `async` including an infinite loop https://github.com/rescript-lang/syntax/pull/680
- Fix issue where certain JSX expressions would be formatted differenctly in compiler 10.1.0-rc.1 https://github.com/rescript-lang/syntax/issues/675
- Fix issue where printing nested pipe discards await https://github.com/rescript-lang/syntax/issues/687

#### :eyeglasses: Spec Compliance

Expand Down
27 changes: 21 additions & 6 deletions src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3604,14 +3604,29 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
| [] -> doc
| _ -> addParens doc
in
let isAwait =
ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes
in
let doc =
Doc.concat
[
leftPrinted;
printBinaryOperator ~inlineRhs:false operator;
rightPrinted;
]
if isAwait then
Doc.concat
[
Doc.text "await ";
Doc.lparen;
leftPrinted;
printBinaryOperator ~inlineRhs:false operator;
rightPrinted;
Doc.rparen;
]
else
Doc.concat
[
leftPrinted;
printBinaryOperator ~inlineRhs:false operator;
rightPrinted;
]
in

let doc =
if (not isLhs) && Parens.rhsBinaryExprOperand operator expr then
Doc.concat [Doc.lparen; doc; Doc.rparen]
Expand Down
3 changes: 3 additions & 0 deletions tests/printer/expr/asyncAwait.res
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ let f11 = (. ~x) => (. ~y) => 3

let f12 = @a (@b x) => 3
let f13 = @a @b (~x) => 3

let aw = (await (server->start))->foo
let aw = (@foo (server->start))->foo
3 changes: 3 additions & 0 deletions tests/printer/expr/expected/asyncAwait.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,6 @@ let f11 = (. ~x) => (. ~y) => 3

let f12 = @a x => 3
let f13 = (@a @b ~x) => 3

let aw = await (server->start)->foo
let aw = @foo (server->start)->foo