Skip to content
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

spec: disable await binding identifier within static block #12661

Merged

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Jan 20, 2021

Q                       A
Fixed Issues? Implements tc39/proposal-class-static-block#32
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR forbids await binding within the static blocks. The logic of arguments check is extended for await binding.

Since async (x = class { static { await; } }) => {} is no longer valid, I also removed the expression scope creation for class static block, since AwaitBindingIdentifierInStaticBlock would be thrown in this case.

@JLHwung JLHwung added PR: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Class Static Block labels Jan 20, 2021
@babel-bot
Copy link
Collaborator

babel-bot commented Jan 20, 2021

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/39150/

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jan 20, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 245b35d:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@JLHwung JLHwung force-pushed the disallow-await-binding-in-static-block branch from bd16c63 to 8fed4f4 Compare January 20, 2021 02:05

C = class { static { function f(x = await) {} } };

C = class { static { function f({ [await]: x }) {} } };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cases that await as binding will not throw.


C = class { static { function await() {} } };

C = class { static { await: 0 } };
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New behaviour: cases that await as binding throws.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Q: How is the context inside of a static block different from the one inside a static field?

@JLHwung
Copy link
Contributor Author

JLHwung commented Jan 29, 2021

Q: How is the context inside of a static block different from the one inside a static field?

Compared to static field (initializer), the static block further blocks await as binding identifier which is allowed in [~Await] production. The motivation is to reserve await and "fail close" so that in the future we may support async static block, parallel to the async constructors.

@JLHwung JLHwung force-pushed the disallow-await-binding-in-static-block branch 2 times, most recently from 9553472 to 4ddaabb Compare January 29, 2021 21:09
@JLHwung
Copy link
Contributor Author

JLHwung commented Jan 29, 2021

The CI error is fixed in #12716. I will rebase once that one is merged.

@JLHwung JLHwung force-pushed the disallow-await-binding-in-static-block branch 2 times, most recently from 1cb34f5 to e698486 Compare January 30, 2021 03:08
@JLHwung
Copy link
Contributor Author

JLHwung commented Jan 30, 2021

Before merging this PR, please review #12716 first. 🙏

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Spec Compliance 👓 A type of pull request used for our changelog categories Spec: Class Static Block
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants