Skip to content

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

Merged
6 commits merged into from
Aug 19, 2016
Merged

Allow await in a simple unary expression #9890

6 commits merged into from
Aug 19, 2016

Conversation

ghost
Copy link

@ghost ghost commented Jul 22, 2016

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 allow typeof await foo.

On the other hand, babel allows typeof await but not typeof yield.

@DanielRosenwasser
Copy link
Member

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:

typeof await x appears to be a valid production from UnaryExpression:

  • UnaryExpression
  • typeof UnaryExpression
  • typeof AwaitExpression
  • typeof await UnaryExpression
  • typeof await UpdateExpression
  • typeof await LeftHandSideExpression
  • typeof await NewExpression
  • typeof await MemberExpression
  • typeof await PrimaryExpression
  • typeof await IdentifierReference
  • typeof await x

typeof yield or typeof yield x is not a valid production because yield and yield AssignmentExpression can only be derived from a YieldExpression, which can only be derived from AssignmentExpression which can't be derived on its own from UnaryExpression.

@@ -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`
Copy link
Member

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 UnaryExpression
  • await AwaitExpression
  • await await UnaryExpression

Copy link
Author

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.

Copy link
Member

@DanielRosenwasser DanielRosenwasser Jul 22, 2016

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]
Copy link
Member

Choose a reason for hiding this comment

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

It's await UnaryExpression

@DanielRosenwasser
Copy link
Member

Other than fixing up that comment, 👍

@ghost ghost merged commit 19cde06 into master Aug 19, 2016
@ghost ghost deleted the cast_of_await branch August 19, 2016 13:49
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants