Skip to content

Commit

Permalink
[estree] Fix conversion of PrivateName in MemberExpression (#13755)
Browse files Browse the repository at this point in the history
* Update test

* [estree] Fix conversion of `PrivateName` in `MemberExpression`
  • Loading branch information
nicolo-ribaudo committed Sep 14, 2021
1 parent 8af57db commit 710b391
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
13 changes: 5 additions & 8 deletions packages/babel-parser/src/plugins/estree.js
Expand Up @@ -181,15 +181,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
classBody.body.push(method);
}

parseMaybePrivateName(...args: [boolean]): any {
const node = super.parseMaybePrivateName(...args);
if (
node.type === "PrivateName" &&
this.getPluginOption("estree", "classFeatures")
) {
return this.convertPrivateNameToPrivateIdentifier(node);
parsePrivateName(): any {
const node = super.parsePrivateName();
if (!this.getPluginOption("estree", "classFeatures")) {
return node;
}
return node;
return this.convertPrivateNameToPrivateIdentifier(node);
}

convertPrivateNameToPrivateIdentifier(
Expand Down
@@ -1,4 +1,8 @@
class A {
#foo = "bar";
static #bar = foo;

method() {
this.#foo;
}
}
@@ -1,15 +1,15 @@
{
"type": "File",
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}},
"start":0,"end":81,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
"program": {
"type": "Program",
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}},
"start":0,"end":81,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ClassDeclaration",
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":4,"column":1}},
"start":0,"end":81,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
"id": {
"type": "Identifier",
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"A"},
Expand All @@ -18,7 +18,7 @@
"superClass": null,
"body": {
"type": "ClassBody",
"start":8,"end":48,"loc":{"start":{"line":1,"column":8},"end":{"line":4,"column":1}},
"start":8,"end":81,"loc":{"start":{"line":1,"column":8},"end":{"line":8,"column":1}},
"body": [
{
"type": "PropertyDefinition",
Expand Down Expand Up @@ -52,6 +52,52 @@
"name": "foo"
},
"computed": false
},
{
"type": "MethodDefinition",
"start":50,"end":79,"loc":{"start":{"line":5,"column":2},"end":{"line":7,"column":3}},
"static": false,
"key": {
"type": "Identifier",
"start":50,"end":56,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":8},"identifierName":"method"},
"name": "method"
},
"computed": false,
"kind": "method",
"value": {
"type": "FunctionExpression",
"start":56,"end":79,"loc":{"start":{"line":5,"column":8},"end":{"line":7,"column":3}},
"id": null,
"generator": false,
"async": false,
"expression": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":59,"end":79,"loc":{"start":{"line":5,"column":11},"end":{"line":7,"column":3}},
"body": [
{
"type": "ExpressionStatement",
"start":65,"end":75,"loc":{"start":{"line":6,"column":4},"end":{"line":6,"column":14}},
"expression": {
"type": "MemberExpression",
"start":65,"end":74,"loc":{"start":{"line":6,"column":4},"end":{"line":6,"column":13}},
"object": {
"type": "ThisExpression",
"start":65,"end":69,"loc":{"start":{"line":6,"column":4},"end":{"line":6,"column":8}}
},
"computed": false,
"property": {
"type": "PrivateIdentifier",
"start":70,"end":74,"loc":{"start":{"line":6,"column":9},"end":{"line":6,"column":13}},
"name": "foo"
},
"optional": false
}
}
]
}
}
}
]
}
Expand Down

0 comments on commit 710b391

Please sign in to comment.