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
add class features #222
add class features #222
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.
Seems reasonable at this phase.
I wonder if the
|
experimental/class-features.md
Outdated
|
||
A private name refers to private class elements. For a private name `#a`, its `id.name` is `a`. | ||
|
||
When the property of a member expression is a private name, its `computed` is always `false`. |
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.
This seems pretty bad. Why not just have a PrivateMemberExpression
? The reason to unify them would be that we expect people to consider them similar for some purpose. I don't expect too much of that.
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.
Some reasons that I can tell
- Babel has
OptionalMemberExpression
which corresponds to OptionalChain PrivateOptionalMemberExpression
forobj?.#x
can be confusing- There is no
PrivateMemberExpression
like production in the spec
I understand the want to align with Unlike the optional chaining changes, which apply to a feature that has only recently been implemented in most of the ecosystem, renaming class properties will be a pretty significant breaking change and will likely be a pretty painful change for users to navigate. |
experimental/class-features.md
Outdated
value: Expression; | ||
computed: boolean; | ||
static: boolean; | ||
private: boolean; |
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.
I love consistency. If we add private:boolean
to (Method|Property)Definition
, I'd like to add it to MemberExpression
as well. Or remove it from both.
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.
I think it's best to remove from both; otherwise we're duplicating same information which explicitly goes against one of the design goeals ("Unique") in the Philosophy.
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.
I agree on @RReverser that we don't need .private
if we can check .key.type === "PrivateIdentifier"
. While I admit that .private
is handier, the ergonomic trade-off here is still acceptable.
Should another private-like key (PrivateComputedExpression
?) be supported in the future, we can introduce .private
at that time.
@bradzacher The |
2cabb33
to
b1ba831
Compare
Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
This comment has been minimized.
This comment has been minimized.
8b9aa92
to
8759fc8
Compare
@RReverser friendly ping, does the current AST design look good to you? |
Oh yeah, sorry, I haven't noticed that |
Sorry, could you clarify how? I don't see how this deviates from the babel AST (or the AST emitted from It looks like the current AST explorer example: TS-ESTree spec (which was built to match the babel implementation): The If that's what the direction going forward is - that's fine. I just want to ensure it's a conscious decision to introduce the breakage. |
The differences between current approach and Babel's approach can be viewed here Notable changes are:
On the AST policy of Babel introduced
Yeah I understand the frictions here, but keep in mind that class proposals are still stage-3, which means they are still experimental, and by nature, open to breaking changes. It's a short time window that we still have opportunities to value long term AST consistency/teachability over short term community frictions. |
@nzakas I think we have reached consensus and it can merged as-is. |
Sounds good! |
In what Babel version will this be available? |
@piranna Babel has different AST shape with ESTree: https://github.com/babel/babel/blob/main/packages/babel-parser/ast/spec.md#classproperty All stage-3 class features are supported on Babel 7.10. |
Sorry, I wanted to say |
View Rendered Text
This PR adds support to three stage-3 class features proposals. It shows Babel's current approach except for the following node type naming differences:
It is named in the
*Definition
pattern, aligning to theMethodDefinition
defined ines2015
.This PR also offers an alternative design of #180. In #180
PrivateMemberExpression
has been introduced forMemberExpression[property=PrivateName]
in this PR, which will have impact on #204 given thatthis?.#priv
is now supported.As the class proposals have been out there for quite some time and they are widely adopted in React/TypeScript communities, especially the class fields proposal, I will expect some tools are depending on Babel class features AST. Building consensus based on this approach can minimize the friction supporting new ESTree releases.
Fixes #154
Closes #180
--- Edits ---
Updated according to review comments. PTAL.