diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b6984cf..6bddeab2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/res_core.ml b/src/res_core.ml index b38430df..d535487d 100644 --- a/src/res_core.ml +++ b/src/res_core.ml @@ -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; @@ -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 *) diff --git a/tests/parsing/grammar/expressions/async.res b/tests/parsing/grammar/expressions/async.res index b104866d..9f33ef2d 100644 --- a/tests/parsing/grammar/expressions/async.res +++ b/tests/parsing/grammar/expressions/async.res @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/tests/parsing/grammar/expressions/expected/async.res.txt b/tests/parsing/grammar/expressions/expected/async.res.txt index 7aef8ffd..eb4424d9 100644 --- a/tests/parsing/grammar/expressions/expected/async.res.txt +++ b/tests/parsing/grammar/expressions/expected/async.res.txt @@ -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 ]) \ No newline at end of file + [@ns.ternary ]) +let foo = async ~a:((34)[@ns.namedArgLoc ]) +let bar = ((fun ~a:((a)[@ns.namedArgLoc ]) -> a + 1)[@res.async ]) \ No newline at end of file diff --git a/tests/printer/expr/asyncAwait.res b/tests/printer/expr/asyncAwait.res index 765e6597..efabc856 100644 --- a/tests/printer/expr/asyncAwait.res +++ b/tests/printer/expr/asyncAwait.res @@ -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 \ No newline at end of file +let aw = (@foo (server->start))->foo + +let foo = async(~a=34) +let bar = async(~a)=>a+1 \ 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 bfd223bc..1082a3d8 100644 --- a/tests/printer/expr/expected/asyncAwait.res.txt +++ b/tests/printer/expr/expected/asyncAwait.res.txt @@ -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