Skip to content

Commit c2fde88

Browse files
committed
Sync latest syntax.
1 parent 1f2505f commit c2fde88

File tree

6 files changed

+87
-27
lines changed

6 files changed

+87
-27
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232

3333
- Fix 5753 the comment for unicode char is inaccurate https://github.com/rescript-lang/syntax/pull/709
3434

35-
- Internal changes: the payload of Pconst_char from char to int type safety. https://github.com/rescript-lang/syntax/pull/709
35+
- Internal changes: the payload of Pconst_char from char to int type safety. https://github.com/rescript-lang/syntax/pull/709
36+
37+
- Treat await as almost-unary operator weaker than pipe so `await foo->bar` means `await (foo->bar)` https://github.com/rescript-lang/syntax/pull/711
3638

3739
# 10.1.0-rc.2
3840

@@ -80,7 +82,6 @@
8082
- Change the internal representation of props for the lowercase components to record. https://github.com/rescript-lang/syntax/pull/665
8183
- Add `JsxPPXReactSupport` module to relocate the helper functions for JSX v4 from `rescript-react`
8284

83-
8485
# 10.1.0-alpha.2
8586

8687
#### :rocket: New Feature

jscomp/napkin/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
- Fix issue where the JSX key type is not an optional string https://github.com/rescript-lang/syntax/pull/693
5151
- Fix issue where the JSX fragment without children build error https://github.com/rescript-lang/syntax/pull/704
5252
- Fix issue where async as an id cannot be used with application and labelled arguments https://github.com/rescript-lang/syntax/issues/707
53-
53+
- Treat await as almost-unary operator weaker than pipe so `await foo->bar` means `await (foo->bar)` https://github.com/rescript-lang/syntax/pull/711
5454

5555
#### :eyeglasses: Spec Compliance
5656

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52146,7 +52146,8 @@ val subBinaryExprOperand : string -> string -> bool
5214652146
val rhsBinaryExprOperand : string -> Parsetree.expression -> bool
5214752147
val flattenOperandRhs : string -> Parsetree.expression -> bool
5214852148

52149-
val lazyOrAssertOrAwaitExprRhs : Parsetree.expression -> kind
52149+
val binaryOperatorInsideAwaitNeedsParens : string -> bool
52150+
val lazyOrAssertOrAwaitExprRhs : ?inAwait:bool -> Parsetree.expression -> kind
5215052151

5215152152
val fieldExpr : Parsetree.expression -> kind
5215252153

@@ -52350,7 +52351,11 @@ let flattenOperandRhs parentOperator rhs =
5235052351
| _ when ParsetreeViewer.isTernaryExpr rhs -> true
5235152352
| _ -> false
5235252353

52353-
let lazyOrAssertOrAwaitExprRhs expr =
52354+
let binaryOperatorInsideAwaitNeedsParens operator =
52355+
ParsetreeViewer.operatorPrecedence operator
52356+
< ParsetreeViewer.operatorPrecedence "|."
52357+
52358+
let lazyOrAssertOrAwaitExprRhs ?(inAwait = false) expr =
5235452359
let optBraces, _ = ParsetreeViewer.processBracesAttr expr in
5235552360
match optBraces with
5235652361
| Some ({Location.loc = bracesLoc}, _) -> Braced bracesLoc
@@ -52361,7 +52366,14 @@ let lazyOrAssertOrAwaitExprRhs expr =
5236152366
| _ :: _ -> true
5236252367
| [] -> false ->
5236352368
Parenthesized
52364-
| expr when ParsetreeViewer.isBinaryExpression expr -> Parenthesized
52369+
| {
52370+
pexp_desc =
52371+
Pexp_apply ({pexp_desc = Pexp_ident {txt = Longident.Lident operator}}, _);
52372+
}
52373+
when ParsetreeViewer.isBinaryExpression expr ->
52374+
if inAwait && not (binaryOperatorInsideAwaitNeedsParens operator) then
52375+
Nothing
52376+
else Parenthesized
5236552377
| {
5236652378
pexp_desc =
5236752379
Pexp_constraint ({pexp_desc = Pexp_pack _}, {ptyp_desc = Ptyp_package _});
@@ -52377,7 +52389,9 @@ let lazyOrAssertOrAwaitExprRhs expr =
5237752389
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
5237852390
} ->
5237952391
Parenthesized
52380-
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes ->
52392+
| _
52393+
when (not inAwait)
52394+
&& ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes ->
5238152395
Parenthesized
5238252396
| _ -> Nothing)
5238352397

@@ -56393,13 +56407,13 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl =
5639356407
if ParsetreeViewer.hasAwaitAttribute e.pexp_attributes then
5639456408
let rhs =
5639556409
match
56396-
Parens.lazyOrAssertOrAwaitExprRhs
56410+
Parens.lazyOrAssertOrAwaitExprRhs ~inAwait:true
5639756411
{
5639856412
e with
5639956413
pexp_attributes =
5640056414
List.filter
5640156415
(function
56402-
| {Location.txt = "res.await" | "ns.braces"}, _ -> false
56416+
| {Location.txt = "ns.braces"}, _ -> false
5640356417
| _ -> true)
5640456418
e.pexp_attributes;
5640556419
}
@@ -56675,13 +56689,18 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
5667556689
in
5667656690
let doc =
5667756691
if isAwait then
56692+
let parens =
56693+
Res_parens.binaryOperatorInsideAwaitNeedsParens operator
56694+
in
5667856695
Doc.concat
5667956696
[
56680-
Doc.text "await ";
5668156697
Doc.lparen;
56698+
Doc.text "await ";
56699+
(if parens then Doc.lparen else Doc.nil);
5668256700
leftPrinted;
5668356701
printBinaryOperator ~inlineRhs:false operator;
5668456702
rightPrinted;
56703+
(if parens then Doc.rparen else Doc.nil);
5668556704
Doc.rparen;
5668656705
]
5668756706
else

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52146,7 +52146,8 @@ val subBinaryExprOperand : string -> string -> bool
5214652146
val rhsBinaryExprOperand : string -> Parsetree.expression -> bool
5214752147
val flattenOperandRhs : string -> Parsetree.expression -> bool
5214852148

52149-
val lazyOrAssertOrAwaitExprRhs : Parsetree.expression -> kind
52149+
val binaryOperatorInsideAwaitNeedsParens : string -> bool
52150+
val lazyOrAssertOrAwaitExprRhs : ?inAwait:bool -> Parsetree.expression -> kind
5215052151

5215152152
val fieldExpr : Parsetree.expression -> kind
5215252153

@@ -52350,7 +52351,11 @@ let flattenOperandRhs parentOperator rhs =
5235052351
| _ when ParsetreeViewer.isTernaryExpr rhs -> true
5235152352
| _ -> false
5235252353

52353-
let lazyOrAssertOrAwaitExprRhs expr =
52354+
let binaryOperatorInsideAwaitNeedsParens operator =
52355+
ParsetreeViewer.operatorPrecedence operator
52356+
< ParsetreeViewer.operatorPrecedence "|."
52357+
52358+
let lazyOrAssertOrAwaitExprRhs ?(inAwait = false) expr =
5235452359
let optBraces, _ = ParsetreeViewer.processBracesAttr expr in
5235552360
match optBraces with
5235652361
| Some ({Location.loc = bracesLoc}, _) -> Braced bracesLoc
@@ -52361,7 +52366,14 @@ let lazyOrAssertOrAwaitExprRhs expr =
5236152366
| _ :: _ -> true
5236252367
| [] -> false ->
5236352368
Parenthesized
52364-
| expr when ParsetreeViewer.isBinaryExpression expr -> Parenthesized
52369+
| {
52370+
pexp_desc =
52371+
Pexp_apply ({pexp_desc = Pexp_ident {txt = Longident.Lident operator}}, _);
52372+
}
52373+
when ParsetreeViewer.isBinaryExpression expr ->
52374+
if inAwait && not (binaryOperatorInsideAwaitNeedsParens operator) then
52375+
Nothing
52376+
else Parenthesized
5236552377
| {
5236652378
pexp_desc =
5236752379
Pexp_constraint ({pexp_desc = Pexp_pack _}, {ptyp_desc = Ptyp_package _});
@@ -52377,7 +52389,9 @@ let lazyOrAssertOrAwaitExprRhs expr =
5237752389
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
5237852390
} ->
5237952391
Parenthesized
52380-
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes ->
52392+
| _
52393+
when (not inAwait)
52394+
&& ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes ->
5238152395
Parenthesized
5238252396
| _ -> Nothing)
5238352397

@@ -56393,13 +56407,13 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl =
5639356407
if ParsetreeViewer.hasAwaitAttribute e.pexp_attributes then
5639456408
let rhs =
5639556409
match
56396-
Parens.lazyOrAssertOrAwaitExprRhs
56410+
Parens.lazyOrAssertOrAwaitExprRhs ~inAwait:true
5639756411
{
5639856412
e with
5639956413
pexp_attributes =
5640056414
List.filter
5640156415
(function
56402-
| {Location.txt = "res.await" | "ns.braces"}, _ -> false
56416+
| {Location.txt = "ns.braces"}, _ -> false
5640356417
| _ -> true)
5640456418
e.pexp_attributes;
5640556419
}
@@ -56675,13 +56689,18 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
5667556689
in
5667656690
let doc =
5667756691
if isAwait then
56692+
let parens =
56693+
Res_parens.binaryOperatorInsideAwaitNeedsParens operator
56694+
in
5667856695
Doc.concat
5667956696
[
56680-
Doc.text "await ";
5668156697
Doc.lparen;
56698+
Doc.text "await ";
56699+
(if parens then Doc.lparen else Doc.nil);
5668256700
leftPrinted;
5668356701
printBinaryOperator ~inlineRhs:false operator;
5668456702
rightPrinted;
56703+
(if parens then Doc.rparen else Doc.nil);
5668556704
Doc.rparen;
5668656705
]
5668756706
else
@@ -286360,7 +286379,8 @@ and parseAwaitExpression p =
286360286379
let awaitLoc = mkLoc p.Parser.startPos p.endPos in
286361286380
let awaitAttr = makeAwaitAttr awaitLoc in
286362286381
Parser.expect Await p;
286363-
let expr = parseUnaryExpr p in
286382+
let tokenPrec = Token.precedence MinusGreater in
286383+
let expr = parseBinaryExpr ~context:OrdinaryExpr p tokenPrec in
286364286384
{
286365286385
expr with
286366286386
pexp_attributes = awaitAttr :: expr.pexp_attributes;

lib/4.06.1/whole_compiler.ml

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228118,7 +228118,8 @@ val subBinaryExprOperand : string -> string -> bool
228118228118
val rhsBinaryExprOperand : string -> Parsetree.expression -> bool
228119228119
val flattenOperandRhs : string -> Parsetree.expression -> bool
228120228120

228121-
val lazyOrAssertOrAwaitExprRhs : Parsetree.expression -> kind
228121+
val binaryOperatorInsideAwaitNeedsParens : string -> bool
228122+
val lazyOrAssertOrAwaitExprRhs : ?inAwait:bool -> Parsetree.expression -> kind
228122228123

228123228124
val fieldExpr : Parsetree.expression -> kind
228124228125

@@ -228322,7 +228323,11 @@ let flattenOperandRhs parentOperator rhs =
228322228323
| _ when ParsetreeViewer.isTernaryExpr rhs -> true
228323228324
| _ -> false
228324228325

228325-
let lazyOrAssertOrAwaitExprRhs expr =
228326+
let binaryOperatorInsideAwaitNeedsParens operator =
228327+
ParsetreeViewer.operatorPrecedence operator
228328+
< ParsetreeViewer.operatorPrecedence "|."
228329+
228330+
let lazyOrAssertOrAwaitExprRhs ?(inAwait = false) expr =
228326228331
let optBraces, _ = ParsetreeViewer.processBracesAttr expr in
228327228332
match optBraces with
228328228333
| Some ({Location.loc = bracesLoc}, _) -> Braced bracesLoc
@@ -228333,7 +228338,14 @@ let lazyOrAssertOrAwaitExprRhs expr =
228333228338
| _ :: _ -> true
228334228339
| [] -> false ->
228335228340
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
228337228349
| {
228338228350
pexp_desc =
228339228351
Pexp_constraint ({pexp_desc = Pexp_pack _}, {ptyp_desc = Ptyp_package _});
@@ -228349,7 +228361,9 @@ let lazyOrAssertOrAwaitExprRhs expr =
228349228361
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
228350228362
} ->
228351228363
Parenthesized
228352-
| _ when ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes ->
228364+
| _
228365+
when (not inAwait)
228366+
&& ParsetreeViewer.hasAwaitAttribute expr.pexp_attributes ->
228353228367
Parenthesized
228354228368
| _ -> Nothing)
228355228369

@@ -232365,13 +232379,13 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl =
232365232379
if ParsetreeViewer.hasAwaitAttribute e.pexp_attributes then
232366232380
let rhs =
232367232381
match
232368-
Parens.lazyOrAssertOrAwaitExprRhs
232382+
Parens.lazyOrAssertOrAwaitExprRhs ~inAwait:true
232369232383
{
232370232384
e with
232371232385
pexp_attributes =
232372232386
List.filter
232373232387
(function
232374-
| {Location.txt = "res.await" | "ns.braces"}, _ -> false
232388+
| {Location.txt = "ns.braces"}, _ -> false
232375232389
| _ -> true)
232376232390
e.pexp_attributes;
232377232391
}
@@ -232647,13 +232661,18 @@ and printBinaryExpression ~customLayout (expr : Parsetree.expression) cmtTbl =
232647232661
in
232648232662
let doc =
232649232663
if isAwait then
232664+
let parens =
232665+
Res_parens.binaryOperatorInsideAwaitNeedsParens operator
232666+
in
232650232667
Doc.concat
232651232668
[
232652-
Doc.text "await ";
232653232669
Doc.lparen;
232670+
Doc.text "await ";
232671+
(if parens then Doc.lparen else Doc.nil);
232654232672
leftPrinted;
232655232673
printBinaryOperator ~inlineRhs:false operator;
232656232674
rightPrinted;
232675+
(if parens then Doc.rparen else Doc.nil);
232657232676
Doc.rparen;
232658232677
]
232659232678
else
@@ -299892,7 +299911,8 @@ and parseAwaitExpression p =
299892299911
let awaitLoc = mkLoc p.Parser.startPos p.endPos in
299893299912
let awaitAttr = makeAwaitAttr awaitLoc in
299894299913
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
299896299916
{
299897299917
expr with
299898299918
pexp_attributes = awaitAttr :: expr.pexp_attributes;

0 commit comments

Comments
 (0)