Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Merge pull request #727 from jridgewell/private-methods
Browse files Browse the repository at this point in the history
classPrivateMethods enables PrivateName usage
  • Loading branch information
existentialism authored Sep 18, 2017
2 parents 9b582c9 + 1f11dc0 commit d016dea
Show file tree
Hide file tree
Showing 34 changed files with 161 additions and 183 deletions.
9 changes: 4 additions & 5 deletions src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
) {
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -652,4 +652,4 @@
],
"directives": []
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateMethods", "asyncGenerators"]
"plugins": ["classPrivateMethods", "asyncGenerators"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -217,4 +217,4 @@
],
"directives": []
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateMethods"]
"plugins": ["classPrivateMethods"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -708,4 +708,4 @@
],
"directives": []
}
}
}
Original file line number Diff line number Diff line change
@@ -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" ]
}
Original file line number Diff line number Diff line change
@@ -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"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -217,4 +217,4 @@
],
"directives": []
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateMethods"]
"plugins": ["classPrivateMethods"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -359,4 +359,4 @@
],
"directives": []
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateMethods"]
"plugins": ["classPrivateMethods"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -201,4 +201,4 @@
],
"directives": []
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateMethods"]
"plugins": ["classPrivateMethods"]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Foo {
#p = x
*#m () {}
*m () {}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"throws": "Unexpected token (3:3)",
"plugins": ["classProperties", "classPrivateProperties"]
"throws": "Unexpected token, expected ; (3:8)",
"plugins": ["classPrivateProperties"]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"throws": "Unexpected token (2:5)",
"plugins": ["classProperties", "classPrivateProperties"]
"plugins": ["classPrivateProperties"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -179,4 +179,4 @@
],
"directives": []
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"plugins": ["classProperties", "classPrivateProperties"]
"plugins": ["classPrivateProperties"]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"throws": "Unexpected token (3:3)",
"plugins": [
"classProperties",
"classPrivateProperties"
]
"plugins": [ "classPrivateProperties" ]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"throws": "Deleting a private field is not allowed (4:4)",
"plugins": [
"classProperties",
"classPrivateProperties"
]
"plugins": [ "classPrivateProperties" ]
}
Original file line number Diff line number Diff line change
@@ -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" ]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"throws": "Unexpected token (2:3)",
"plugins": [
"classProperties",
"classPrivateProperties"
]
"plugins": [ "classPrivateProperties" ]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"throws": "Identifier directly after number (2:4)",
"plugins": ["classProperties", "classPrivateProperties"]
"plugins": ["classPrivateProperties"]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"throws": "Unexpected token (4:11)",
"plugins": [
"classProperties",
"classPrivateProperties"
]
"plugins": [ "classPrivateProperties" ]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"throws": "Unexpected token (2:3)",
"plugins": [
"classProperties",
"classPrivateProperties"
]
"plugins": [ "classPrivateProperties" ]
}
Loading

0 comments on commit d016dea

Please sign in to comment.