[estree] Fix conversion of PrivateName in MemberExpression (#13755)
* Update test * [estree] Fix conversion of `PrivateName` in `MemberExpression`
This commit is contained in:
parent
8af57dbfb7
commit
710b3919fa
@ -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(
|
||||
|
||||
@ -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"},
|
||||
@ -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",
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user