Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[estree] Fix conversion of PrivateName in MemberExpression #13755

Merged
merged 2 commits into from Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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