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

Fix issue where async as an id cannot be used with application and la… #708

Merged
merged 2 commits into from
Oct 28, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
- Fix issue where printing nested pipe discards await https://github.com/rescript-lang/syntax/issues/687
- Fix issue where the JSX key type is not an optional string https://github.com/rescript-lang/syntax/pull/693
- Fix issue where the JSX fragment withouth children build error https://github.com/rescript-lang/syntax/pull/704
- Fix issue where async as an id cannot be used with application and labelled arguments https://github.com/rescript-lang/syntax/issues/707


#### :eyeglasses: Spec Compliance

Expand Down
12 changes: 8 additions & 4 deletions src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,13 @@ let rec goToClosing closingToken state =
(* Madness *)
let isEs6ArrowExpression ~inTernary p =
Parser.lookahead p (fun state ->
(match state.Parser.token with
| Lident "async" -> Parser.next state
| _ -> ());
let async =
match state.Parser.token with
| Lident "async" ->
Parser.next state;
true
| _ -> false
in
match state.Parser.token with
| Lident _ | Underscore -> (
Parser.next state;
Expand Down Expand Up @@ -275,7 +279,7 @@ let isEs6ArrowExpression ~inTernary p =
| EqualGreater -> true
| _ -> false)
| Dot (* uncurried *) -> true
| Tilde -> true
| Tilde when not async -> true
| Backtick ->
false
(* (` always indicates the start of an expr, can't be es6 parameter *)
Expand Down
5 changes: 4 additions & 1 deletion tests/parsing/grammar/expressions/async.res
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ let async = {
result->async->mapAsync(a => doStuff(a))
}

let f = isPositive ? (async (a, b) : int => a + b) : async (c, d) : int => c - d
let f = isPositive ? (async (a, b) : int => a + b) : async (c, d) : int => c - d

let foo = async(~a=34)
let bar = async(~a)=>a+1
4 changes: 3 additions & 1 deletion tests/parsing/grammar/expressions/expected/async.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ let f =
((if isPositive
then ((fun a -> fun b -> (a + b : int))[@res.async ])
else (((fun c -> fun d -> (c - d : int)))[@res.async ]))
[@ns.ternary ])
[@ns.ternary ])
let foo = async ~a:((34)[@ns.namedArgLoc ])
let bar = ((fun ~a:((a)[@ns.namedArgLoc ]) -> a + 1)[@res.async ])
5 changes: 4 additions & 1 deletion tests/printer/expr/asyncAwait.res
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,7 @@ let f12 = @a (@b x) => 3
let f13 = @a @b (~x) => 3

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

let foo = async(~a=34)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be more appropriate in the tests/parsing/grammar/expressions/async directory as it's really about parsing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did that first but wanted to check that it does not mess up printing.
Probably both.

let bar = async(~a)=>a+1
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 @@ -121,3 +121,6 @@ let f13 = (@a @b ~x) => 3

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

let foo = async(~a=34)
let bar = async (~a) => a + 1