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

fix: do not transform ClassPrivateMethods in estree #11973

Merged
merged 2 commits into from Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 22 additions & 0 deletions eslint/babel-eslint-tests/test/integration/eslint/eslint.js
Expand Up @@ -1758,6 +1758,28 @@ describe("verify", () => {
{ "no-unused-vars": 1 },
);
});

it("should visit params", () => {
verifyAndAssertMessages(
`export class C {
constructor() { this.#d(); }
#d(unused) {};
}
`,
{ "no-unused-vars": 1 },
);
});

it("should visit body", () => {
verifyAndAssertMessages(
`export class C {
constructor() { this.#d(); }
#d() { var unused; };
}
`,
{ "no-unused-vars": 1 },
);
});
});
});

Expand Down
13 changes: 13 additions & 0 deletions packages/babel-parser/src/plugins/estree.js
Expand Up @@ -287,6 +287,19 @@ export default (superClass: Class<Parser>): Class<Parser> =>
type: string,
inClassScope: boolean = false,
): T {
if (type === "ClassPrivateMethod") {
// todo: supports ClassPrivateMethod
// see https://github.com/estree/estree/blob/master/experimental/class-features.md
return super.parseMethod(
node,
isGenerator,
isAsync,
isConstructor,
allowDirectSuper,
type,
inClassScope,
);
}
let funcNode = this.startNode();
funcNode.kind = node.kind; // provide kind, so super method correctly sets state
funcNode = super.parseMethod(
Expand Down
@@ -0,0 +1,3 @@
class A {
#foo(arg, ...others) {}
}
@@ -0,0 +1,3 @@
{
"plugins": ["flow", "jsx", "estree", "classPrivateMethods"]
}
@@ -0,0 +1,68 @@
{
"type": "File",
"start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"program": {
"type": "Program",
"start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"sourceType": "script",
"interpreter": null,
"body": [
{
"type": "ClassDeclaration",
"start":0,"end":37,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"id": {
"type": "Identifier",
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"A"},
"name": "A"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start":8,"end":37,"loc":{"start":{"line":1,"column":8},"end":{"line":3,"column":1}},
"body": [
{
"type": "ClassPrivateMethod",
"start":12,"end":35,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":25}},
"static": false,
"key": {
"type": "PrivateName",
"start":12,"end":16,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":6}},
"id": {
"type": "Identifier",
"start":13,"end":16,"loc":{"start":{"line":2,"column":3},"end":{"line":2,"column":6},"identifierName":"foo"},
"name": "foo"
}
},
"kind": "method",
"id": null,
"generator": false,
"async": false,
"expression": false,
"params": [
{
"type": "Identifier",
"start":17,"end":20,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":10},"identifierName":"arg"},
"name": "arg"
},
{
"type": "RestElement",
"start":22,"end":31,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":21}},
"argument": {
"type": "Identifier",
"start":25,"end":31,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":21},"identifierName":"others"},
"name": "others"
}
}
],
"body": {
"type": "BlockStatement",
"start":33,"end":35,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":25}},
"body": []
}
}
]
}
}
]
}
}