diff --git a/CHANGELOG.md b/CHANGELOG.md index 26273502..87a36ca1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/res_printer.ml b/src/res_printer.ml index 8a0bf8cc..f3625e88 100644 --- a/src/res_printer.ml +++ b/src/res_printer.ml @@ -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] diff --git a/tests/printer/expr/asyncAwait.res b/tests/printer/expr/asyncAwait.res index 32c77349..765e6597 100644 --- a/tests/printer/expr/asyncAwait.res +++ b/tests/printer/expr/asyncAwait.res @@ -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 \ No newline at end of file diff --git a/tests/printer/expr/expected/asyncAwait.res.txt b/tests/printer/expr/expected/asyncAwait.res.txt index 01dab207..bfd223bc 100644 --- a/tests/printer/expr/expected/asyncAwait.res.txt +++ b/tests/printer/expr/expected/asyncAwait.res.txt @@ -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