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

added check to disallow super.private variable access and test case added #10472

Merged
merged 7 commits into from Sep 20, 2019
9 changes: 9 additions & 0 deletions packages/babel-parser/src/parser/expression.js
Expand Up @@ -655,6 +655,15 @@ export default class ExpressionParser extends LValParser {
node.object = base;
node.property = this.parseMaybePrivateName();
node.computed = false;
if (
node.property.type === "PrivateName" &&
node.object.type === "Super"
) {
this.raise(
startPos,
"super is not allowed to be called on a private identifier of a class",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, in this case super is not being called (it's not super(#x)).
What about Private fields can't be accessed on super?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that message makes more sense. I will make the changes accordingly and also update the tests. Thank you

);
}
if (state.optionalChainMember) {
node.optional = false;
return this.finishNode(node, "OptionalMemberExpression");
Expand Down
@@ -0,0 +1,7 @@
class A extends B {
#x;

method() {
super.#x;
}
}
@@ -0,0 +1,6 @@
{
"plugins": [
"classPrivateProperties"
],
"throws": "super is not allowed to be called on a private identifier of a class (5:4)"
}