Karl Cheng 65bea96544 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
2017-09-06 18:09:12 -04:00

368 lines
8.7 KiB
JSON

{
"type": "File",
"start": 0,
"end": 48,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 27
}
},
"program": {
"type": "Program",
"start": 0,
"end": 48,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 27
}
},
"sourceType": "script",
"body": [
{
"type": "ClassDeclaration",
"start": 0,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 19
}
},
"id": {
"type": "Identifier",
"start": 6,
"end": 7,
"loc": {
"start": {
"line": 1,
"column": 6
},
"end": {
"line": 1,
"column": 7
},
"identifierName": "A"
},
"name": "A"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 8,
"end": 19,
"loc": {
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 19
}
},
"body": [
{
"type": "ClassPrivateProperty",
"start": 10,
"end": 13,
"loc": {
"start": {
"line": 1,
"column": 10
},
"end": {
"line": 1,
"column": 13
}
},
"static": false,
"key": {
"type": "PrivateName",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
}
},
"id": {
"type": "Identifier",
"start": 11,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
},
"identifierName": "x"
},
"name": "x"
}
},
"value": null
},
{
"type": "ClassPrivateProperty",
"start": 14,
"end": 17,
"loc": {
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 17
}
},
"static": false,
"key": {
"type": "PrivateName",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 16
}
},
"id": {
"type": "Identifier",
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 16
},
"identifierName": "y"
},
"name": "y"
}
},
"value": null
}
]
}
},
{
"type": "ClassDeclaration",
"start": 21,
"end": 48,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 27
}
},
"id": {
"type": "Identifier",
"start": 27,
"end": 28,
"loc": {
"start": {
"line": 3,
"column": 6
},
"end": {
"line": 3,
"column": 7
},
"identifierName": "B"
},
"name": "B"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 29,
"end": 48,
"loc": {
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 3,
"column": 27
}
},
"body": [
{
"type": "ClassPrivateProperty",
"start": 31,
"end": 38,
"loc": {
"start": {
"line": 3,
"column": 10
},
"end": {
"line": 3,
"column": 17
}
},
"static": false,
"key": {
"type": "PrivateName",
"start": 32,
"end": 33,
"loc": {
"start": {
"line": 3,
"column": 11
},
"end": {
"line": 3,
"column": 12
}
},
"id": {
"type": "Identifier",
"start": 32,
"end": 33,
"loc": {
"start": {
"line": 3,
"column": 11
},
"end": {
"line": 3,
"column": 12
},
"identifierName": "x"
},
"name": "x"
}
},
"value": {
"type": "NumericLiteral",
"start": 36,
"end": 37,
"loc": {
"start": {
"line": 3,
"column": 15
},
"end": {
"line": 3,
"column": 16
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
},
{
"type": "ClassPrivateProperty",
"start": 39,
"end": 46,
"loc": {
"start": {
"line": 3,
"column": 18
},
"end": {
"line": 3,
"column": 25
}
},
"static": false,
"key": {
"type": "PrivateName",
"start": 40,
"end": 41,
"loc": {
"start": {
"line": 3,
"column": 19
},
"end": {
"line": 3,
"column": 20
}
},
"id": {
"type": "Identifier",
"start": 40,
"end": 41,
"loc": {
"start": {
"line": 3,
"column": 19
},
"end": {
"line": 3,
"column": 20
},
"identifierName": "y"
},
"name": "y"
}
},
"value": {
"type": "NumericLiteral",
"start": 44,
"end": 45,
"loc": {
"start": {
"line": 3,
"column": 23
},
"end": {
"line": 3,
"column": 24
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
]
}
}
],
"directives": []
}
}