-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Allow await
in a simple unary expression
#9890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Please add tests for both of the cases you pointed out. Also, in the future you should consult the bleeding edge spec and spec proposals over any runtimes:
|
@@ -3337,7 +3337,10 @@ namespace ts { | |||
function parseAwaitExpression() { | |||
const node = <AwaitExpression>createNode(SyntaxKind.AwaitExpression); | |||
nextToken(); | |||
node.expression = parseSimpleUnaryExpression(); | |||
node.expression = token === SyntaxKind.AwaitKeyword | |||
// Forbid `await await` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is await await
forbidden?
- UnaryExpression
- AwaitExpression
await
UnaryExpressionawait
AwaitExpressionawait
await
UnaryExpression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the spec it looked like 'await' was specifically exempted from following. Maybe I read that wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently it is not possible for an AwaitExpression and a YieldExpression to be parsed together, so technically passing the ?Yield parameter for UnaryExpression: [+Await]
await
UnaryExpression[?Yield, Await] is unnecessary. It will probably be useful for AsyncGenerators however.
yield
expressions and await
expressions can't be mixed because since async generators aren't really a thing at this point, so whether or not it's a valid parse is kind of moot.
Keep in mind, await yield
is valid in a plain async
function. yield
would be parsed as an identifier right there.
If you did have asynchronous generators, yield await 10
would be valid in those contexts, but await yield
would not - you'd need to parenthesized the yield
keyword.
@@ -3386,6 +3386,7 @@ namespace ts { | |||
* 6) - UnaryExpression[?yield] | |||
* 7) ~ UnaryExpression[?yield] | |||
* 8) ! UnaryExpression[?yield] | |||
* 9) [+Await] await AwaitExpression[?yield] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's await
UnaryExpression
Other than fixing up that comment, 👍 |
Fixes #9877
However, this may not be up to the ES spec. Node.js does not allow
typeof yield foo
, so it may be wrong to allowtypeof await foo
.On the other hand, babel allows
typeof await
but nottypeof yield
.