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

Commit 54118b3

Browse files
authored
Fix issue where async as an id cannot be used with application and la… (#708)
* Fix issue where async as an id cannot be used with application and labelled arguments. Fixes #707 * Add parsing test.
1 parent 7b2ed1b commit 54118b3

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
- Fix issue where printing nested pipe discards await https://github.com/rescript-lang/syntax/issues/687
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 withouth children build error https://github.com/rescript-lang/syntax/pull/704
52+
- Fix issue where async as an id cannot be used with application and labelled arguments https://github.com/rescript-lang/syntax/issues/707
53+
5254

5355
#### :eyeglasses: Spec Compliance
5456

src/res_core.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,13 @@ let rec goToClosing closingToken state =
232232
(* Madness *)
233233
let isEs6ArrowExpression ~inTernary p =
234234
Parser.lookahead p (fun state ->
235-
(match state.Parser.token with
236-
| Lident "async" -> Parser.next state
237-
| _ -> ());
235+
let async =
236+
match state.Parser.token with
237+
| Lident "async" ->
238+
Parser.next state;
239+
true
240+
| _ -> false
241+
in
238242
match state.Parser.token with
239243
| Lident _ | Underscore -> (
240244
Parser.next state;
@@ -275,7 +279,7 @@ let isEs6ArrowExpression ~inTernary p =
275279
| EqualGreater -> true
276280
| _ -> false)
277281
| Dot (* uncurried *) -> true
278-
| Tilde -> true
282+
| Tilde when not async -> true
279283
| Backtick ->
280284
false
281285
(* (` always indicates the start of an expr, can't be es6 parameter *)

tests/parsing/grammar/expressions/async.res

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ let async = {
2626
result->async->mapAsync(a => doStuff(a))
2727
}
2828

29-
let f = isPositive ? (async (a, b) : int => a + b) : async (c, d) : int => c - d
29+
let f = isPositive ? (async (a, b) : int => a + b) : async (c, d) : int => c - d
30+
31+
let foo = async(~a=34)
32+
let bar = async(~a)=>a+1

tests/parsing/grammar/expressions/expected/async.res.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ let f =
2525
((if isPositive
2626
then ((fun a -> fun b -> (a + b : int))[@res.async ])
2727
else (((fun c -> fun d -> (c - d : int)))[@res.async ]))
28-
[@ns.ternary ])
28+
[@ns.ternary ])
29+
let foo = async ~a:((34)[@ns.namedArgLoc ])
30+
let bar = ((fun ~a:((a)[@ns.namedArgLoc ]) -> a + 1)[@res.async ])

tests/printer/expr/asyncAwait.res

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,7 @@ let f12 = @a (@b x) => 3
9898
let f13 = @a @b (~x) => 3
9999

100100
let aw = (await (server->start))->foo
101-
let aw = (@foo (server->start))->foo
101+
let aw = (@foo (server->start))->foo
102+
103+
let foo = async(~a=34)
104+
let bar = async(~a)=>a+1

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,6 @@ let f13 = (@a @b ~x) => 3
121121

122122
let aw = await (server->start)->foo
123123
let aw = @foo (server->start)->foo
124+
125+
let foo = async(~a=34)
126+
let bar = async (~a) => a + 1

0 commit comments

Comments
 (0)