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

Commit d64839e

Browse files
authored
Fix issue where printing nested pipe discards await (#688)
1 parent 202b8a9 commit d64839e

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
- Fix issue where the formatter would delete `async` in a function with labelled arguments.
4343
- Fix several printing issues with `async` including an infinite loop https://github.com/rescript-lang/syntax/pull/680
4444
- 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
45+
- Fix issue where printing nested pipe discards await https://github.com/rescript-lang/syntax/issues/687
4546

4647
#### :eyeglasses: Spec Compliance
4748

src/res_printer.ml

+21-6
Original file line numberDiff line numberDiff line change
@@ -3604,14 +3604,29 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
36043604
| [] -> doc
36053605
| _ -> addParens doc
36063606
in
3607+
let isAwait =
3608+
ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes
3609+
in
36073610
let doc =
3608-
Doc.concat
3609-
[
3610-
leftPrinted;
3611-
printBinaryOperator ~inlineRhs:false operator;
3612-
rightPrinted;
3613-
]
3611+
if isAwait then
3612+
Doc.concat
3613+
[
3614+
Doc.text "await ";
3615+
Doc.lparen;
3616+
leftPrinted;
3617+
printBinaryOperator ~inlineRhs:false operator;
3618+
rightPrinted;
3619+
Doc.rparen;
3620+
]
3621+
else
3622+
Doc.concat
3623+
[
3624+
leftPrinted;
3625+
printBinaryOperator ~inlineRhs:false operator;
3626+
rightPrinted;
3627+
]
36143628
in
3629+
36153630
let doc =
36163631
if (not isLhs) && Parens.rhsBinaryExprOperand operator expr then
36173632
Doc.concat [Doc.lparen; doc; Doc.rparen]

tests/printer/expr/asyncAwait.res

+3
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,6 @@ let f11 = (. ~x) => (. ~y) => 3
9696

9797
let f12 = @a (@b x) => 3
9898
let f13 = @a @b (~x) => 3
99+
100+
let aw = (await (server->start))->foo
101+
let aw = (@foo (server->start))->foo

tests/printer/expr/expected/asyncAwait.res.txt

+3
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,6 @@ let f11 = (. ~x) => (. ~y) => 3
118118

119119
let f12 = @a x => 3
120120
let f13 = (@a @b ~x) => 3
121+
122+
let aw = await (server->start)->foo
123+
let aw = @foo (server->start)->foo

0 commit comments

Comments
 (0)