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

add class features #222

Merged
merged 10 commits into from Jul 7, 2020
67 changes: 67 additions & 0 deletions experimental/class-features.md
@@ -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;
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

}
```

- 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