classPrivateMethods enables PrivateName usage

This separates `classPrivateMethods`'s dependency on
`classPrivateProperties`. It also starts a `PrivateName` at the hash
symbol, not the `Identifier`.
This commit is contained in:
Justin Ridgewell 2017-09-17 21:24:37 -04:00
parent 4df30fc300
commit 1f11dc0881
34 changed files with 161 additions and 183 deletions

View File

@ -348,7 +348,6 @@ export default class ExpressionParser extends LValParser {
if (arg.type === "Identifier") {
this.raise(node.start, "Deleting local variable in strict mode");
} else if (
this.hasPlugin("classPrivateProperties") &&
arg.type === "MemberExpression" &&
arg.property.type === "PrivateName"
) {
@ -471,9 +470,7 @@ export default class ExpressionParser extends LValParser {
} else if (this.eat(tt.dot)) {
const node = this.startNodeAt(startPos, startLoc);
node.object = base;
node.property = this.hasPlugin("classPrivateProperties")
? this.parseMaybePrivateName()
: this.parseIdentifier(true);
node.property = this.parseMaybePrivateName();
node.computed = false;
return this.finishNode(node, "MemberExpression");
} else if (this.eat(tt.bracketL)) {
@ -809,10 +806,12 @@ export default class ExpressionParser extends LValParser {
}
parseMaybePrivateName(): N.PrivateName | N.Identifier {
const isPrivate = this.eat(tt.hash);
const isPrivate = this.match(tt.hash);
if (isPrivate) {
this.expectOnePlugin(["classPrivateProperties", "classPrivateMethods"]);
const node = this.startNode();
this.next();
node.id = this.parseIdentifier(true);
return this.finishNode(node, "PrivateName");
} else {

View File

@ -92,12 +92,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 22,
"start": 21,
"end": 31,
"loc": {
"start": {
"line": 2,
"column": 10
"column": 9
},
"end": {
"line": 2,
@ -652,4 +652,4 @@
],
"directives": []
}
}
}

View File

@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateMethods", "asyncGenerators"]
"plugins": ["classPrivateMethods", "asyncGenerators"]
}

View File

@ -92,12 +92,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 23,
"start": 22,
"end": 27,
"loc": {
"start": {
"line": 2,
"column": 9
"column": 8
},
"end": {
"line": 2,
@ -217,4 +217,4 @@
],
"directives": []
}
}
}

View File

@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateMethods"]
"plugins": ["classPrivateMethods"]
}

View File

@ -147,12 +147,12 @@
"kind": "method",
"key": {
"type": "PrivateName",
"start": 26,
"start": 25,
"end": 27,
"loc": {
"start": {
"line": 4,
"column": 4
"column": 3
},
"end": {
"line": 4,
@ -282,12 +282,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 57,
"start": 56,
"end": 58,
"loc": {
"start": {
"line": 8,
"column": 3
"column": 2
},
"end": {
"line": 8,
@ -443,12 +443,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 99,
"start": 98,
"end": 100,
"loc": {
"start": {
"line": 11,
"column": 7
"column": 6
},
"end": {
"line": 11,
@ -566,12 +566,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 122,
"start": 121,
"end": 123,
"loc": {
"start": {
"line": 13,
"column": 3
"column": 2
},
"end": {
"line": 13,
@ -708,4 +708,4 @@
],
"directives": []
}
}
}

View File

@ -1,7 +1,4 @@
{
"throws": "Classes may not have a private field named '#constructor' (2:3)",
"plugins": [
"classProperties",
"classPrivateMethods"
]
"throws": "Classes may not have a private field named '#constructor' (2:2)",
"plugins": [ "classPrivateMethods" ]
}

View File

@ -1,4 +1,4 @@
{
"throws": "This experimental syntax requires enabling the parser plugin: 'classPrivateMethods' (3:3)",
"plugins": ["classProperties", "classPrivateProperties"]
"throws": "This experimental syntax requires enabling the parser plugin: 'classPrivateMethods' (3:2)",
"plugins": ["classPrivateProperties"]
}

View File

@ -93,12 +93,12 @@
"kind": "method",
"key": {
"type": "PrivateName",
"start": 18,
"start": 17,
"end": 22,
"loc": {
"start": {
"line": 2,
"column": 4
"column": 3
},
"end": {
"line": 2,
@ -217,4 +217,4 @@
],
"directives": []
}
}
}

View File

@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateMethods"]
"plugins": ["classPrivateMethods"]
}

View File

@ -92,12 +92,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 21,
"start": 20,
"end": 25,
"loc": {
"start": {
"line": 2,
"column": 7
"column": 6
},
"end": {
"line": 2,
@ -213,12 +213,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 60,
"start": 59,
"end": 64,
"loc": {
"start": {
"line": 5,
"column": 7
"column": 6
},
"end": {
"line": 5,
@ -359,4 +359,4 @@
],
"directives": []
}
}
}

View File

@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateMethods"]
"plugins": ["classPrivateMethods"]
}

View File

@ -92,12 +92,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 17,
"start": 16,
"end": 26,
"loc": {
"start": {
"line": 2,
"column": 3
"column": 2
},
"end": {
"line": 2,
@ -201,4 +201,4 @@
],
"directives": []
}
}
}

View File

@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateMethods"]
"plugins": ["classPrivateMethods"]
}

View File

@ -1,4 +1,4 @@
class Foo {
#p = x
*#m () {}
*m () {}
}

View File

@ -1,4 +1,4 @@
{
"throws": "Unexpected token (3:3)",
"plugins": ["classProperties", "classPrivateProperties"]
"throws": "Unexpected token, expected ; (3:8)",
"plugins": ["classPrivateProperties"]
}

View File

@ -1,4 +1,4 @@
{
"throws": "Unexpected token (2:5)",
"plugins": ["classProperties", "classPrivateProperties"]
"plugins": ["classPrivateProperties"]
}

View File

@ -92,12 +92,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 15,
"start": 14,
"end": 16,
"loc": {
"start": {
"line": 2,
"column": 3
"column": 2
},
"end": {
"line": 2,
@ -141,12 +141,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 20,
"start": 19,
"end": 21,
"loc": {
"start": {
"line": 3,
"column": 3
"column": 2
},
"end": {
"line": 3,
@ -179,4 +179,4 @@
],
"directives": []
}
}
}

View File

@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateProperties"]
"plugins": ["classPrivateProperties"]
}

View File

@ -1,7 +1,4 @@
{
"throws": "Unexpected token (3:3)",
"plugins": [
"classProperties",
"classPrivateProperties"
]
"plugins": [ "classPrivateProperties" ]
}

View File

@ -1,7 +1,4 @@
{
"throws": "Deleting a private field is not allowed (4:4)",
"plugins": [
"classProperties",
"classPrivateProperties"
]
"plugins": [ "classPrivateProperties" ]
}

View File

@ -1,7 +1,4 @@
{
"throws": "Classes may not have a private field named '#constructor' (2:3)",
"plugins": [
"classProperties",
"classPrivateProperties"
]
"throws": "Classes may not have a private field named '#constructor' (2:2)",
"plugins": [ "classPrivateProperties" ]
}

View File

@ -1,7 +1,4 @@
{
"throws": "Unexpected token (2:3)",
"plugins": [
"classProperties",
"classPrivateProperties"
]
"plugins": [ "classPrivateProperties" ]
}

View File

@ -1,4 +1,4 @@
{
"throws": "Identifier directly after number (2:4)",
"plugins": ["classProperties", "classPrivateProperties"]
"plugins": ["classPrivateProperties"]
}

View File

@ -1,7 +1,4 @@
{
"throws": "Unexpected token (4:11)",
"plugins": [
"classProperties",
"classPrivateProperties"
]
"plugins": [ "classPrivateProperties" ]
}

View File

@ -1,7 +1,4 @@
{
"throws": "Unexpected token (2:3)",
"plugins": [
"classProperties",
"classPrivateProperties"
]
"plugins": [ "classPrivateProperties" ]
}

View File

@ -92,12 +92,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 11,
"start": 10,
"end": 12,
"loc": {
"start": {
"line": 1,
"column": 11
"column": 10
},
"end": {
"line": 1,
@ -141,12 +141,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 15,
"start": 14,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 15
"column": 14
},
"end": {
"line": 1,
@ -240,12 +240,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 32,
"start": 31,
"end": 33,
"loc": {
"start": {
"line": 3,
"column": 11
"column": 10
},
"end": {
"line": 3,
@ -308,12 +308,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 40,
"start": 39,
"end": 41,
"loc": {
"start": {
"line": 3,
"column": 19
"column": 18
},
"end": {
"line": 3,
@ -365,4 +365,4 @@
],
"directives": []
}
}
}

View File

@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateProperties"]
"plugins": ["classPrivateProperties"]
}

View File

@ -92,12 +92,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 17,
"start": 16,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 3
"column": 2
},
"end": {
"line": 2,
@ -160,12 +160,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 27,
"start": 26,
"end": 28,
"loc": {
"start": {
"line": 3,
"column": 3
"column": 2
},
"end": {
"line": 3,
@ -430,12 +430,12 @@
},
"property": {
"type": "PrivateName",
"start": 75,
"start": 74,
"end": 76,
"loc": {
"start": {
"line": 6,
"column": 10
"column": 9
},
"end": {
"line": 6,
@ -561,12 +561,12 @@
},
"property": {
"type": "PrivateName",
"start": 93,
"start": 92,
"end": 94,
"loc": {
"start": {
"line": 7,
"column": 10
"column": 9
},
"end": {
"line": 7,
@ -757,12 +757,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 132,
"start": 131,
"end": 133,
"loc": {
"start": {
"line": 10,
"column": 7
"column": 6
},
"end": {
"line": 10,
@ -825,12 +825,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 146,
"start": 145,
"end": 147,
"loc": {
"start": {
"line": 11,
"column": 7
"column": 6
},
"end": {
"line": 11,
@ -1095,12 +1095,12 @@
},
"property": {
"type": "PrivateName",
"start": 202,
"start": 201,
"end": 203,
"loc": {
"start": {
"line": 14,
"column": 14
"column": 13
},
"end": {
"line": 14,
@ -1226,12 +1226,12 @@
},
"property": {
"type": "PrivateName",
"start": 224,
"start": 223,
"end": 225,
"loc": {
"start": {
"line": 15,
"column": 14
"column": 13
},
"end": {
"line": 15,
@ -1400,12 +1400,12 @@
},
"property": {
"type": "PrivateName",
"start": 270,
"start": 269,
"end": 271,
"loc": {
"start": {
"line": 18,
"column": 29
"column": 28
},
"end": {
"line": 18,
@ -1569,12 +1569,12 @@
},
"property": {
"type": "PrivateName",
"start": 301,
"start": 300,
"end": 302,
"loc": {
"start": {
"line": 19,
"column": 27
"column": 26
},
"end": {
"line": 19,
@ -1743,12 +1743,12 @@
},
"property": {
"type": "PrivateName",
"start": 344,
"start": 343,
"end": 345,
"loc": {
"start": {
"line": 21,
"column": 29
"column": 28
},
"end": {
"line": 21,
@ -1912,12 +1912,12 @@
},
"property": {
"type": "PrivateName",
"start": 375,
"start": 374,
"end": 376,
"loc": {
"start": {
"line": 22,
"column": 27
"column": 26
},
"end": {
"line": 22,
@ -2132,12 +2132,12 @@
},
"property": {
"type": "PrivateName",
"start": 420,
"start": 419,
"end": 421,
"loc": {
"start": {
"line": 24,
"column": 31
"column": 30
},
"end": {
"line": 24,
@ -2198,12 +2198,12 @@
},
"property": {
"type": "PrivateName",
"start": 429,
"start": 428,
"end": 430,
"loc": {
"start": {
"line": 24,
"column": 40
"column": 39
},
"end": {
"line": 24,
@ -2277,12 +2277,12 @@
},
"property": {
"type": "PrivateName",
"start": 440,
"start": 439,
"end": 441,
"loc": {
"start": {
"line": 24,
"column": 51
"column": 50
},
"end": {
"line": 24,
@ -2343,12 +2343,12 @@
},
"property": {
"type": "PrivateName",
"start": 449,
"start": 448,
"end": 450,
"loc": {
"start": {
"line": 24,
"column": 60
"column": 59
},
"end": {
"line": 24,
@ -2496,12 +2496,12 @@
},
"property": {
"type": "PrivateName",
"start": 496,
"start": 495,
"end": 497,
"loc": {
"start": {
"line": 26,
"column": 42
"column": 41
},
"end": {
"line": 26,
@ -2559,12 +2559,12 @@
},
"property": {
"type": "PrivateName",
"start": 509,
"start": 508,
"end": 510,
"loc": {
"start": {
"line": 26,
"column": 55
"column": 54
},
"end": {
"line": 26,
@ -2768,12 +2768,12 @@
},
"property": {
"type": "PrivateName",
"start": 554,
"start": 553,
"end": 555,
"loc": {
"start": {
"line": 30,
"column": 25
"column": 24
},
"end": {
"line": 30,
@ -2937,12 +2937,12 @@
},
"property": {
"type": "PrivateName",
"start": 581,
"start": 580,
"end": 582,
"loc": {
"start": {
"line": 31,
"column": 23
"column": 22
},
"end": {
"line": 31,
@ -3111,12 +3111,12 @@
},
"property": {
"type": "PrivateName",
"start": 620,
"start": 619,
"end": 621,
"loc": {
"start": {
"line": 33,
"column": 25
"column": 24
},
"end": {
"line": 33,
@ -3280,12 +3280,12 @@
},
"property": {
"type": "PrivateName",
"start": 647,
"start": 646,
"end": 648,
"loc": {
"start": {
"line": 34,
"column": 23
"column": 22
},
"end": {
"line": 34,
@ -3500,12 +3500,12 @@
},
"property": {
"type": "PrivateName",
"start": 688,
"start": 687,
"end": 689,
"loc": {
"start": {
"line": 36,
"column": 27
"column": 26
},
"end": {
"line": 36,
@ -3566,12 +3566,12 @@
},
"property": {
"type": "PrivateName",
"start": 697,
"start": 696,
"end": 698,
"loc": {
"start": {
"line": 36,
"column": 36
"column": 35
},
"end": {
"line": 36,
@ -3645,12 +3645,12 @@
},
"property": {
"type": "PrivateName",
"start": 708,
"start": 707,
"end": 709,
"loc": {
"start": {
"line": 36,
"column": 47
"column": 46
},
"end": {
"line": 36,
@ -3711,12 +3711,12 @@
},
"property": {
"type": "PrivateName",
"start": 717,
"start": 716,
"end": 718,
"loc": {
"start": {
"line": 36,
"column": 56
"column": 55
},
"end": {
"line": 36,
@ -3864,12 +3864,12 @@
},
"property": {
"type": "PrivateName",
"start": 760,
"start": 759,
"end": 761,
"loc": {
"start": {
"line": 38,
"column": 38
"column": 37
},
"end": {
"line": 38,
@ -3927,12 +3927,12 @@
},
"property": {
"type": "PrivateName",
"start": 773,
"start": 772,
"end": 774,
"loc": {
"start": {
"line": 38,
"column": 51
"column": 50
},
"end": {
"line": 38,
@ -4034,4 +4034,4 @@
],
"directives": []
}
}
}

View File

@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateProperties"]
"plugins": ["classPrivateProperties"]
}

View File

@ -92,12 +92,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 17,
"start": 16,
"end": 18,
"loc": {
"start": {
"line": 2,
"column": 3
"column": 2
},
"end": {
"line": 2,
@ -160,12 +160,12 @@
"static": false,
"key": {
"type": "PrivateName",
"start": 27,
"start": 26,
"end": 28,
"loc": {
"start": {
"line": 3,
"column": 3
"column": 2
},
"end": {
"line": 3,
@ -430,12 +430,12 @@
},
"property": {
"type": "PrivateName",
"start": 75,
"start": 74,
"end": 76,
"loc": {
"start": {
"line": 6,
"column": 10
"column": 9
},
"end": {
"line": 6,
@ -561,12 +561,12 @@
},
"property": {
"type": "PrivateName",
"start": 93,
"start": 92,
"end": 94,
"loc": {
"start": {
"line": 7,
"column": 10
"column": 9
},
"end": {
"line": 7,
@ -735,12 +735,12 @@
},
"property": {
"type": "PrivateName",
"start": 131,
"start": 130,
"end": 132,
"loc": {
"start": {
"line": 10,
"column": 25
"column": 24
},
"end": {
"line": 10,
@ -904,12 +904,12 @@
},
"property": {
"type": "PrivateName",
"start": 158,
"start": 157,
"end": 159,
"loc": {
"start": {
"line": 11,
"column": 23
"column": 22
},
"end": {
"line": 11,
@ -1078,12 +1078,12 @@
},
"property": {
"type": "PrivateName",
"start": 197,
"start": 196,
"end": 198,
"loc": {
"start": {
"line": 13,
"column": 25
"column": 24
},
"end": {
"line": 13,
@ -1247,12 +1247,12 @@
},
"property": {
"type": "PrivateName",
"start": 224,
"start": 223,
"end": 225,
"loc": {
"start": {
"line": 14,
"column": 23
"column": 22
},
"end": {
"line": 14,
@ -1467,12 +1467,12 @@
},
"property": {
"type": "PrivateName",
"start": 265,
"start": 264,
"end": 266,
"loc": {
"start": {
"line": 16,
"column": 27
"column": 26
},
"end": {
"line": 16,
@ -1533,12 +1533,12 @@
},
"property": {
"type": "PrivateName",
"start": 274,
"start": 273,
"end": 275,
"loc": {
"start": {
"line": 16,
"column": 36
"column": 35
},
"end": {
"line": 16,
@ -1612,12 +1612,12 @@
},
"property": {
"type": "PrivateName",
"start": 285,
"start": 284,
"end": 286,
"loc": {
"start": {
"line": 16,
"column": 47
"column": 46
},
"end": {
"line": 16,
@ -1678,12 +1678,12 @@
},
"property": {
"type": "PrivateName",
"start": 294,
"start": 293,
"end": 295,
"loc": {
"start": {
"line": 16,
"column": 56
"column": 55
},
"end": {
"line": 16,
@ -1831,12 +1831,12 @@
},
"property": {
"type": "PrivateName",
"start": 337,
"start": 336,
"end": 338,
"loc": {
"start": {
"line": 18,
"column": 38
"column": 37
},
"end": {
"line": 18,
@ -1894,12 +1894,12 @@
},
"property": {
"type": "PrivateName",
"start": 350,
"start": 349,
"end": 351,
"loc": {
"start": {
"line": 18,
"column": 51
"column": 50
},
"end": {
"line": 18,
@ -2001,4 +2001,4 @@
],
"directives": []
}
}
}

View File

@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateProperties"]
"plugins": ["classPrivateProperties"]
}

View File

@ -92,12 +92,12 @@
"static": true,
"key": {
"type": "PrivateName",
"start": 20,
"start": 19,
"end": 21,
"loc": {
"start": {
"line": 2,
"column": 10
"column": 9
},
"end": {
"line": 2,
@ -141,12 +141,12 @@
"static": true,
"key": {
"type": "PrivateName",
"start": 33,
"start": 32,
"end": 34,
"loc": {
"start": {
"line": 3,
"column": 10
"column": 9
},
"end": {
"line": 3,
@ -198,4 +198,4 @@
],
"directives": []
}
}
}

View File

@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateProperties"]
"plugins": ["classPrivateProperties"]
}