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

Implement class features in estree #12370

Merged
merged 10 commits into from Feb 21, 2021

Conversation

JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Nov 17, 2020

Q                       A
Fixed Issues? Fixes #12282, fixes #12105
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR implements https://github.com/estree/estree/blob/master/experimental/class-features.md given that class features are stage 3 and shipped in several engines (V8, JSC, Gecko).

Note that ESLint does not support class features yet because Acorn has not yet implemented this proposal, though it supports a variant AST shape via acorn-class-features.

Eventually Acorn will support the AST shape supported in this PR since once class features are merged to ESTree. Hence we went ahead and implement this proposal in the estree plugin.

Support of ESTree class features is still experimental, Babel may change the class features AST if, when the ESTree proposal merged, the AST shapes differs, though it is very unlikely as far as I know.

This PR includes commits in #12375.

@babel-bot
Copy link
Collaborator

babel-bot commented Nov 17, 2020

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

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 17, 2020

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 9d36a74:

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

@JLHwung JLHwung force-pushed the implement-class-features-in-estree branch from 4a293e3 to e4ae011 Compare November 18, 2020 22:58
@JLHwung JLHwung marked this pull request as ready for review November 19, 2020 16:01
@JLHwung JLHwung added the PR: New Feature 🚀 A type of pull request used for our changelog categories label Nov 19, 2020
@JLHwung JLHwung force-pushed the implement-class-features-in-estree branch from 0c98726 to 714e834 Compare November 19, 2020 23:56
@nicolo-ribaudo nicolo-ribaudo added this to the v7.13.0 milestone Nov 20, 2020
@JLHwung JLHwung force-pushed the implement-class-features-in-estree branch 2 times, most recently from 8e4fb27 to abd06d9 Compare December 9, 2020 15:39
@JLHwung JLHwung force-pushed the implement-class-features-in-estree branch from abd06d9 to 227e1d1 Compare February 1, 2021 22:58
@JLHwung JLHwung force-pushed the implement-class-features-in-estree branch from 227e1d1 to ba7afc8 Compare February 16, 2021 14:57
@kaicataldo
Copy link
Member

Support of ESTree class features is still experimental, Babel may change the class features AST if, when the ESTree proposal merged, the AST shapes differs, though it is very unlikely as far as I know.

Do we know how we want to handle a situation like this? Are we going to wait until major versions to change the AST or add options or something? Just want to make sure we don't break any plugins that rely on the current AST shape.

@nicolo-ribaudo
Copy link
Member

So far we have always considered these changes as "new features" and shipped them in minors enabled by default: the contract of the "estree" option is "I want Babel to generate an AST that respects the ESTree spec", so if the ESTree spec changes not aligning with it is a bug (similarly, when the ECMAScript spec changes we introduce the breaking change to align as a bugfix).

However, I wouldn't be opposed to something like ["estree", { "classFeatures": true }] until Babel 8.

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

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

Code looks good to me - just a few questions for clarity!

packages/babel-parser/src/plugins/estree.js Show resolved Hide resolved
packages/babel-parser/src/plugins/flow/index.js Outdated Show resolved Hide resolved
@JLHwung
Copy link
Contributor Author

JLHwung commented Feb 19, 2021

The class features ESTree proposal has been moved to stage 3 recently: estree/estree#242, which means unless the spec undergoes significant change, the current ESTree AST shape will not change. See also https://github.com/estree/estree/blob/master/stage3/README.md

@nicolo-ribaudo
Copy link
Member

Q: Does eslint support this natively now?

@kaicataldo
Copy link
Member

I haven't been involved in a few months, but, last I checked, ESLint's policy is to not crash on stage 3 syntax. Rules aren't updated for new syntax until they hit stage 4.

@ljharb
Copy link
Member

ljharb commented Feb 19, 2021

No, sadly they're still insisting on waiting til stage 4 to support things that have already shipped in browsers and node.

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

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

I have a few small suggestions for improving the clarity of comments, but the code LGTM!

class A {
#foo = "bar";
static isA(obj) {
return #foo in obj;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the estree private brand checks proposal is also moved to stage 3. I just add a test case for private-in.

@nicolo-ribaudo nicolo-ribaudo added the PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release label Feb 19, 2021
This was referenced Mar 15, 2021
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 24, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: eslint area: estree outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser PR: New Feature 🚀 A type of pull request used for our changelog categories PR: Ready to be Merged A pull request with already two approvals, but waiting for the next minor release
Projects
None yet
5 participants