Skip to content
This repository was archived by the owner on Sep 8, 2021. It is now read-only.
This repository was archived by the owner on Sep 8, 2021. It is now read-only.

Why not allow await? #24

@bakkot

Description

@bakkot

It's surprising to me that this forbids await. I'd expect to be able to do anything I could do in the surrounding code, including initialization of the class itself which might require waiting for some asynchronous operation.

Note that you can already await in computed property names:

(async () => class {
  [await 0](){}
})()

is legal today.

This can't just be legalized in a followup because it interacts with parsing: if the await flag is not passed to the static block, then

class A {
  static {
    console.log(await);
  }
}

is syntactically legal even in an async context. To keep the possibility of legalizing this open, at the very least we'd need to pass the correct grammar flag today and just make AwaitExpression an error. But it seems both simpler and more useful to inherit async-ness from the surrounding context.

(Edit: I should mention that similar concerns apply to yield, though the parsing isn't as tricky.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions