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

Support multiple static blocks #12738

Merged
merged 5 commits into from Mar 12, 2021
Merged

Conversation

@JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Feb 2, 2021

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

I will not mark this PR as ready until the upstream PR is merged.

The integration test about new.target is disabled because of #12737. Yet the test of static-blocks is still valid because we transform static blocks to static private field initializers.

@babel-bot
Copy link
Collaborator

@babel-bot babel-bot commented Feb 2, 2021

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

@codesandbox
Copy link

@codesandbox codesandbox bot commented Feb 2, 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 e002f53:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration
@JLHwung JLHwung force-pushed the JLHwung:multiple-static-blocks branch from ddbc630 to 0c990d4 Feb 2, 2021
@JLHwung JLHwung force-pushed the JLHwung:multiple-static-blocks branch from 0c990d4 to d661b37 Mar 8, 2021
@JLHwung JLHwung marked this pull request as ready for review Mar 8, 2021
Copy link
Contributor Author

@JLHwung JLHwung left a comment

It's been a while and I complete forget the context of this PR.

This PR looks good to me except that we should avoid shadowing upper private identifiers.

@@ -1528,6 +1528,5 @@ export type ParseSubscriptState = {

export type ParseClassMemberState = {|
hadConstructor: boolean,
hadStaticBlock: boolean,

This comment has been minimized.

@JLHwung

JLHwung Mar 8, 2021
Author Contributor

The parser types are not exported, so we are free to refactor here.

return;
for (const path of body) {
if (!path.isStaticBlock()) continue;
const staticBlockPrivateId = generateUid(scope, privateNames);

This comment has been minimized.

@JLHwung

JLHwung Mar 8, 2021
Author Contributor

The inserted unique staticBlockPrivateId may accidentally shadow private id defined on upper levels:

class C {
  static #_;
  constructor() {
    class D {
      static {
        C.#_ = 42;
      }
    }
  }
}

The injected #_ = AIIFE(static block) will shadow #_ defined on C. Consider reuse the privateNameVisitorFactory in @babel/helper-create-class-features-plugin.

This comment has been minimized.

@jridgewell

jridgewell Mar 8, 2021
Member

Why don't we just use the filename + source location to generate a private name?

This comment has been minimized.

@JLHwung

JLHwung Mar 8, 2021
Author Contributor

That does not really solve the mentioned issue, just makes it way less likely to happen. I don't think this is a blocker and we can address that in another PR.

This comment has been minimized.

@nicolo-ribaudo

nicolo-ribaudo Mar 10, 2021
Member

We should probably consider tracking private identifiers in @babel/traverse's generateUid.

This comment has been minimized.

@JLHwung

JLHwung Mar 10, 2021
Author Contributor

Or we provide a new generateUniquePrivateKeyAPI since plain identifier does not conflict with private identifiers.

@nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Mar 12, 2021

Let's do #12738 (comment) in a separate PR, since it happens regardless of multiple static blocks.

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Can you add an input/output test with multiple static blocks?

@JLHwung JLHwung force-pushed the JLHwung:multiple-static-blocks branch from d661b37 to e002f53 Mar 12, 2021
@nicolo-ribaudo nicolo-ribaudo merged commit 1a05b81 into babel:main Mar 12, 2021
24 of 26 checks passed
24 of 26 checks passed
@github-actions
Prepare Cache
Details
@github-actions
Test on Node.js Latest
Details
@github-actions
Build Babel Artifacts
Details
@github-actions
Test Babel 8 breaking changes
Details
@github-actions
Publish to local Verdaccio registry
Details
@github-actions
Lint
Details
@github-actions
Test on Node.js (14)
Details
@github-actions
Test on Node.js (12)
Details
@github-actions
Test on Node.js (10)
Details
@github-actions
Test on Node.js (8)
Details
@github-actions
Test on Node.js (6)
Details
@github-actions
Test on Windows
Details
@github-actions
Third-party Parser Tests
Details
@github-actions
Test @babel/runtime integrations
Details
@github-actions
E2E (babel)
Details
@github-actions
E2E (babel-old-version)
Details
@github-actions
E2E (create-react-app)
Details
@github-actions
E2E (vue-cli)
Details
@github-actions
E2E (jest)
Details
@circleci-checks
e2e-breaking-pr Workflow: e2e-breaking-pr
Details
@circleci-checks
test262-pr Workflow: test262-pr
Details
@gitpod-io
Gitpod Open an online workspace in Gitpod
Details
@babel-bot
babel/repl REPL preview is available
Details
@circleci-checks
build-standalone Workflow: build-standalone
Details
@codesandbox
ci/codesandbox Building packages succeeded.
Details
@codecov
codecov/project 91.41% (target 90.00%)
Details
@nicolo-ribaudo nicolo-ribaudo deleted the JLHwung:multiple-static-blocks branch Mar 12, 2021
This was referenced Mar 16, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants