@@ -228118,7 +228118,8 @@ val subBinaryExprOperand : string -> string -> bool
228118
228118
val rhsBinaryExprOperand : string -> Parsetree.expression -> bool
228119
228119
val flattenOperandRhs : string -> Parsetree.expression -> bool
228120
228120
228121
- val lazyOrAssertOrAwaitExprRhs : Parsetree.expression -> kind
228121
+ val binaryOperatorInsideAwaitNeedsParens : string -> bool
228122
+ val lazyOrAssertOrAwaitExprRhs : ?inAwait:bool -> Parsetree.expression -> kind
228122
228123
228123
228124
val fieldExpr : Parsetree.expression -> kind
228124
228125
@@ -228322,7 +228323,11 @@ let flattenOperandRhs parentOperator rhs =
228322
228323
| _ when ParsetreeViewer.isTernaryExpr rhs -> true
228323
228324
| _ -> false
228324
228325
228325
- let lazyOrAssertOrAwaitExprRhs expr =
228326
+ let binaryOperatorInsideAwaitNeedsParens operator =
228327
+ ParsetreeViewer.operatorPrecedence operator
228328
+ < ParsetreeViewer.operatorPrecedence "|."
228329
+
228330
+ let lazyOrAssertOrAwaitExprRhs ?(inAwait = false) expr =
228326
228331
let optBraces, _ = ParsetreeViewer.processBracesAttr expr in
228327
228332
match optBraces with
228328
228333
| Some ({Location.loc = bracesLoc}, _) -> Braced bracesLoc
@@ -228333,7 +228338,14 @@ let lazyOrAssertOrAwaitExprRhs expr =
228333
228338
| _ :: _ -> true
228334
228339
| [] -> false ->
228335
228340
Parenthesized
228336
- | expr when ParsetreeViewer.isBinaryExpression expr -> Parenthesized
228341
+ | {
228342
+ pexp_desc =
228343
+ Pexp_apply ({pexp_desc = Pexp_ident {txt = Longident.Lident operator}}, _);
228344
+ }
228345
+ when ParsetreeViewer.isBinaryExpression expr ->
228346
+ if inAwait && not (binaryOperatorInsideAwaitNeedsParens operator) then
228347
+ Nothing
228348
+ else Parenthesized
228337
228349
| {
228338
228350
pexp_desc =
228339
228351
Pexp_constraint ({pexp_desc = Pexp_pack _}, {ptyp_desc = Ptyp_package _});
@@ -228349,7 +228361,9 @@ let lazyOrAssertOrAwaitExprRhs expr =
228349
228361
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
228350
228362
} ->
228351
228363
Parenthesized
228352
- | _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes ->
228364
+ | _
228365
+ when (not inAwait)
228366
+ && ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes ->
228353
228367
Parenthesized
228354
228368
| _ -> Nothing)
228355
228369
@@ -232365,13 +232379,13 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl =
232365
232379
if ParsetreeViewer.hasAwaitAttribute e.pexp_attributes then
232366
232380
let rhs =
232367
232381
match
232368
- Parens.lazyOrAssertOrAwaitExprRhs
232382
+ Parens.lazyOrAssertOrAwaitExprRhs ~inAwait:true
232369
232383
{
232370
232384
e with
232371
232385
pexp_attributes =
232372
232386
List.filter
232373
232387
(function
232374
- | {Location.txt = "res.await" | " ns.braces"}, _ -> false
232388
+ | {Location.txt = "ns.braces"}, _ -> false
232375
232389
| _ -> true)
232376
232390
e.pexp_attributes;
232377
232391
}
@@ -232647,13 +232661,18 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
232647
232661
in
232648
232662
let doc =
232649
232663
if isAwait then
232664
+ let parens =
232665
+ Res_parens.binaryOperatorInsideAwaitNeedsParens operator
232666
+ in
232650
232667
Doc.concat
232651
232668
[
232652
- Doc.text "await ";
232653
232669
Doc.lparen;
232670
+ Doc.text "await ";
232671
+ (if parens then Doc.lparen else Doc.nil);
232654
232672
leftPrinted;
232655
232673
printBinaryOperator ~inlineRhs:false operator;
232656
232674
rightPrinted;
232675
+ (if parens then Doc.rparen else Doc.nil);
232657
232676
Doc.rparen;
232658
232677
]
232659
232678
else
@@ -299892,7 +299911,8 @@ and parseAwaitExpression p =
299892
299911
let awaitLoc = mkLoc p.Parser.startPos p.endPos in
299893
299912
let awaitAttr = makeAwaitAttr awaitLoc in
299894
299913
Parser.expect Await p;
299895
- let expr = parseUnaryExpr p in
299914
+ let tokenPrec = Token.precedence MinusGreater in
299915
+ let expr = parseBinaryExpr ~context:OrdinaryExpr p tokenPrec in
299896
299916
{
299897
299917
expr with
299898
299918
pexp_attributes = awaitAttr :: expr.pexp_attributes;
0 commit comments