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
Merged
Merged
add class features #222
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5c442f1
add class features
JLHwung 886847c
Merge PrivateDefinition and PublicDefinition
JLHwung ec27102
add private: boolean to MemberExpression
JLHwung de6148e
initializer is optional
JLHwung 0125693
update PrivateName interface
JLHwung b1ba831
refine text
JLHwung 083f826
Update experimental/class-features.md
JLHwung 19f342e
address review comments
JLHwung 04a2841
PrivateName => PrivateIdentifier
JLHwung 8759fc8
remove `private` property with respect to the Unique philosophy
JLHwung File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
# Class Features | ||
|
||
This experimental extension covers three class features proposals: | ||
[Class Fields], [Static Class Features] and [Private Methods]. | ||
|
||
## ClassBody | ||
|
||
```js | ||
extend interface ClassBody { | ||
body: [ MethodDefinition | PropertyDefinition ]; | ||
} | ||
``` | ||
|
||
## PropertyDefinition | ||
|
||
```js | ||
interface PropertyDefinition <: Node { | ||
type: "PropertyDefinition"; | ||
key: Expression | PrivateName; | ||
value: Expression | null; | ||
computed: boolean; | ||
static: boolean; | ||
private: boolean; | ||
} | ||
``` | ||
|
||
- When `private` is `true`, `computed` must be `false` and `key` must be a `PrivateName`. | ||
- When `private` is `false`, `key` must be an `Expression` and can not be a `PrivateName`. | ||
|
||
## MethodDefinition | ||
|
||
```js | ||
extend interface MethodDefinition { | ||
key: Expression | PrivateName; | ||
private: boolean; | ||
} | ||
``` | ||
|
||
- When `private` is `true`, `computed` must be `false`, `key` must be a `PrivateName`, `kind` can not be `"constructor"`. | ||
- When `private` is `false`, `key` must be an `Expression` and can not be a `PrivateName`. | ||
|
||
### PrivateName | ||
|
||
```js | ||
interface PrivateName <: Node { | ||
JLHwung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
type: "PrivateName"; | ||
name: string; | ||
} | ||
``` | ||
|
||
A private name refers to private class elements. For a private name `#a`, its `name` is `a`. | ||
|
||
```js | ||
extend interface MemberExpression { | ||
private: boolean; | ||
property: Expression | PrivateName; | ||
} | ||
``` | ||
|
||
- When `private` is `true`, `property` must be a `PrivateName`, `computed` must be `false`. | ||
- When `private` is `false`, `property` must be an `Expression` and can not be a `PrivateName`. | ||
- When `object` is a `Super`, `private` must be `false`. | ||
|
||
[Class Fields]: https://github.com/tc39/proposal-class-fields | ||
[Static Class Features]: https://github.com/tc39/proposal-static-class-features/ | ||
[Private Methods]: https://github.com/tc39/proposal-private-methods |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 toMemberExpression
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.