Modify grammar to support Private Fields proposal: (#260)
* Modify grammar to support Private Fields proposal: - Adding optional plugin `classPrivateProperties` - Adding PrivateName type identifier - Adding ClassPrivateProperty to ClassBody - Allow PrivateName in MemberExpression - Allow PrivateName as a reference - Adding tests * Remove unnecesary liberal parameter * Guarding for plugin dependecy for future versioning * update spec.md [skip ci] * move comment [skip ci] * remove unused param [skip ci] * Refactor PrivateName to contain Identifier in name property
This commit is contained in:
committed by
Henry Zhu
parent
6c4acecf00
commit
01da62283c
4
test/fixtures/experimental/class-private-properties/asi-failure-computed/actual.js
vendored
Normal file
4
test/fixtures/experimental/class-private-properties/asi-failure-computed/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
#p = x
|
||||
[#m] () {}
|
||||
}
|
||||
7
test/fixtures/experimental/class-private-properties/asi-failure-computed/options.json
vendored
Normal file
7
test/fixtures/experimental/class-private-properties/asi-failure-computed/options.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"throws": "Unexpected token, expected ; (3:10)",
|
||||
"plugins": [
|
||||
"classProperties",
|
||||
"classPrivateProperties"
|
||||
]
|
||||
}
|
||||
4
test/fixtures/experimental/class-private-properties/asi-failure-generator/actual.js
vendored
Normal file
4
test/fixtures/experimental/class-private-properties/asi-failure-generator/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
#p = x
|
||||
*#m () {}
|
||||
}
|
||||
4
test/fixtures/experimental/class-private-properties/asi-failure-generator/options.json
vendored
Normal file
4
test/fixtures/experimental/class-private-properties/asi-failure-generator/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"throws": "Unexpected token, expected ; (3:9)",
|
||||
"plugins": ["classProperties", "classPrivateProperties"]
|
||||
}
|
||||
3
test/fixtures/experimental/class-private-properties/asi-failure-inline/actual.js
vendored
Normal file
3
test/fixtures/experimental/class-private-properties/asi-failure-inline/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
#x #y
|
||||
}
|
||||
4
test/fixtures/experimental/class-private-properties/asi-failure-inline/options.json
vendored
Normal file
4
test/fixtures/experimental/class-private-properties/asi-failure-inline/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"throws": "Unexpected token, expected ; (2:5)",
|
||||
"plugins": ["classProperties", "classPrivateProperties"]
|
||||
}
|
||||
4
test/fixtures/experimental/class-private-properties/asi-success/actual.js
vendored
Normal file
4
test/fixtures/experimental/class-private-properties/asi-success/actual.js
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
class Foo {
|
||||
#x
|
||||
#y
|
||||
}
|
||||
152
test/fixtures/experimental/class-private-properties/asi-success/expected.json
vendored
Normal file
152
test/fixtures/experimental/class-private-properties/asi-success/expected.json
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"sourceType": "script",
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassDeclaration",
|
||||
"start": 0,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 6,
|
||||
"end": 9,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 6
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 9
|
||||
},
|
||||
"identifierName": "Foo"
|
||||
},
|
||||
"name": "Foo"
|
||||
},
|
||||
"superClass": null,
|
||||
"body": {
|
||||
"type": "ClassBody",
|
||||
"start": 10,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 10
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "ClassPrivateProperty",
|
||||
"start": 14,
|
||||
"end": 16,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 4
|
||||
}
|
||||
},
|
||||
"computed": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 15,
|
||||
"end": 16,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 3
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 4
|
||||
},
|
||||
"identifierName": "x"
|
||||
},
|
||||
"name": "x"
|
||||
},
|
||||
"value": null
|
||||
},
|
||||
{
|
||||
"type": "ClassPrivateProperty",
|
||||
"start": 19,
|
||||
"end": 21,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 4
|
||||
}
|
||||
},
|
||||
"computed": false,
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 20,
|
||||
"end": 21,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 3
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 4
|
||||
},
|
||||
"identifierName": "y"
|
||||
},
|
||||
"name": "y"
|
||||
},
|
||||
"value": null
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
3
test/fixtures/experimental/class-private-properties/asi-success/options.json
vendored
Normal file
3
test/fixtures/experimental/class-private-properties/asi-success/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["classProperties", "classPrivateProperties"]
|
||||
}
|
||||
3
test/fixtures/experimental/class-private-properties/inline/actual.js
vendored
Normal file
3
test/fixtures/experimental/class-private-properties/inline/actual.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
class A { #x; #y; }
|
||||
|
||||
class B { #x = 0; #y = 1; }
|
||||
308
test/fixtures/experimental/class-private-properties/inline/expected.json
vendored
Normal file
308
test/fixtures/experimental/class-private-properties/inline/expected.json
vendored
Normal file
@@ -0,0 +1,308 @@
|
||||
{
|
||||
"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
|
||||
}
|
||||
},
|
||||
"computed": false,
|
||||
"key": {
|
||||
"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
|
||||
}
|
||||
},
|
||||
"computed": false,
|
||||
"key": {
|
||||
"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
|
||||
}
|
||||
},
|
||||
"computed": false,
|
||||
"key": {
|
||||
"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
|
||||
}
|
||||
},
|
||||
"computed": false,
|
||||
"key": {
|
||||
"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": []
|
||||
}
|
||||
}
|
||||
3
test/fixtures/experimental/class-private-properties/inline/options.json
vendored
Normal file
3
test/fixtures/experimental/class-private-properties/inline/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["classProperties", "classPrivateProperties"]
|
||||
}
|
||||
19
test/fixtures/experimental/class-private-properties/pbn-success.1/actual.js
vendored
Normal file
19
test/fixtures/experimental/class-private-properties/pbn-success.1/actual.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
class Point {
|
||||
#x;
|
||||
#y;
|
||||
|
||||
constructor(x = 0, y = 0) {
|
||||
#x = +x;
|
||||
#y = +y;
|
||||
}
|
||||
|
||||
get x() { return this.#x }
|
||||
set x(value) { this.#x = +value }
|
||||
|
||||
get y() { return this.#y }
|
||||
set y(value) { this.#y = +value }
|
||||
|
||||
equals(p) { return this.#x === p.#x && this.#y === p.#y }
|
||||
|
||||
toString() { return `Point<${ this.#x },${ this.#y }>` }
|
||||
}
|
||||
1874
test/fixtures/experimental/class-private-properties/pbn-success.1/expected.json
vendored
Normal file
1874
test/fixtures/experimental/class-private-properties/pbn-success.1/expected.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3
test/fixtures/experimental/class-private-properties/pbn-success.1/options.json
vendored
Normal file
3
test/fixtures/experimental/class-private-properties/pbn-success.1/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["classProperties", "classPrivateProperties"]
|
||||
}
|
||||
19
test/fixtures/experimental/class-private-properties/pbn-success/actual.js
vendored
Normal file
19
test/fixtures/experimental/class-private-properties/pbn-success/actual.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
class Point {
|
||||
#x;
|
||||
#y;
|
||||
|
||||
constructor(x = 0, y = 0) {
|
||||
#x = +x;
|
||||
#y = +y;
|
||||
}
|
||||
|
||||
get x() { return #x }
|
||||
set x(value) { #x = +value }
|
||||
|
||||
get y() { return #y }
|
||||
set y(value) { #y = +value }
|
||||
|
||||
equals(p) { return #x === p.#x && #y === p.#y }
|
||||
|
||||
toString() { return `Point<${ #x },${ #y }>` }
|
||||
}
|
||||
1626
test/fixtures/experimental/class-private-properties/pbn-success/expected.json
vendored
Normal file
1626
test/fixtures/experimental/class-private-properties/pbn-success/expected.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3
test/fixtures/experimental/class-private-properties/pbn-success/options.json
vendored
Normal file
3
test/fixtures/experimental/class-private-properties/pbn-success/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["classProperties", "classPrivateProperties"]
|
||||
}
|
||||
Reference in New Issue
Block a user