Add support for class private methods (#703)

* Add support for class private methods

This commit adds parser support for the TC39 Stage 2 Private Methods
proposal.

This commit also changes "key" in ClassPrivateProperty from an
Identifier to a PrivateName, as well as disallowing #constructor as a
valid private field name.

* Add tests for string literal get/set/async

These should be treated as regular methods and not special get/set/async
behaviour.

* Add tests for class private methods

This also removes a test from the Test262 whitelist that failed before
the changes for private methods support and now passes.

* Modify class private prop tests for PrivateName

* Add class private prop tests for #constructor

* Fix existing ASI test case failure
This commit is contained in:
Karl Cheng
2017-09-07 08:09:12 +10:00
committed by Justin Ridgewell
parent b65b5a2f1c
commit 65bea96544
54 changed files with 3430 additions and 425 deletions

View File

@@ -90,6 +90,7 @@ These are the core Babylon AST node types.
- [Classes](#classes)
- [ClassBody](#classbody)
- [ClassMethod](#classmethod)
- [ClassPrivateMethod](#classprivatemethod)
- [ClassProperty](#classproperty)
- [ClassPrivateProperty](#classprivateproperty)
- [ClassDeclaration](#classdeclaration)
@@ -1032,7 +1033,7 @@ interface Class <: Node {
```js
interface ClassBody <: Node {
type: "ClassBody";
body: [ ClassMethod | ClassProperty | ClassPrivateProperty ];
body: [ ClassMethod | ClassPrivateMethod | ClassProperty | ClassPrivateProperty ];
}
```
@@ -1049,6 +1050,18 @@ interface ClassMethod <: Function {
}
```
## ClassPrivateMethod
```js
interface ClassPrivateMethod <: Function {
type: "ClassPrivateMethod";
key: PrivateName;
kind: "method" | "get" | "set";
static: boolean;
decorators: [ Decorator ];
}
```
## ClassProperty
```js
@@ -1066,7 +1079,7 @@ interface ClassProperty <: Node {
```js
interface ClassPrivateProperty <: Node {
type: "ClassPrivateProperty";
key: Identifier;
key: PrivateName;
value: Expression;
static: boolean;
}