-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
fix: Class Field Initializer should not allow await expression as immediate child #10946
Conversation
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.
Do we have tests for await
inside computed keys? I tried searching [await
but couldn't find them.
async function f() {
class A {
[await 1]() {}
}
}
@nicolo-ribaudo Test is added. The computed properties are not affected here because it is never in the class scope. The class scope are applied to the property initializer and the method body. But I feel like if we really want to be 100% spec compliant, we should introduce |
This PR fixes the
isAwaitAllowed
logic by excludingawait
identifier reference immediately nested in a class property initializer.Per https://tc39.es/proposal-class-fields/#sec-new-syntax
the spec dictates that the
Initializer
can not containIdentifierReference_Yield
orIdentifierReference_Await
, which meansawait
should be considered as identifier reference here, unless its[Await]
parameter is enabled by other language structures.The original snippet in #6687
will still throw because
await
is an identifier instead of await expression, but not because the constructor is not an async function. Think of the following example, which should still throw even the static property does not need a constructor to initialize.Note that we have a similar issue regarding to the generators:
Parsing the following code should throw because
yield
is an identifier, which turns out to be a reserved word since it resides in a class declaration where all parts are in strict code mode.I will address this in a separate PR.