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
Correctly access shadowed class binding in super.*
#12544
Correctly access shadowed class binding in super.*
#12544
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/37187/ |
return; | ||
} | ||
|
||
if (path.scope.hasOwnBinding(classState.classRef.name)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/**
* Replace the constructor body of our class.
*/
function pushConstructor(
superReturns,
method: { type: "ClassMethod" },
path: NodePath,
) {
// https://github.com/babel/babel/issues/1077
if (path.scope.hasOwnBinding(classState.classRef.name)) {
path.scope.rename(classState.classRef.name);
}
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to traverse here because super
may appear anywhere in methods.
Edit: Ooops, super
may appear anywhere in constructors too.
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 79395d9:
|
I think that we need to move this logic in class A extends B {
method() {
let A;
super.#foo();
}
} |
I agree on moving logic in ReplaceSupers but can't see why the example should work: derived classes should have no access to private methods of Base classes, right? Only public and protected methods are accessible. |
...ages/babel-helper-create-class-features-plugin/test/fixtures/replace-supers/static/output.js
Outdated
Show resolved
Hide resolved
It can work in cases like class B {
#foo = 3;
static getA() {
class A extends B {
method() {
let A;
super.#foo();
}
}
}
} |
Really? Tried it on chrome 87, got: |
Sorry, I was completely wrong 🙃
class A extends B {
#foo() {
let A;
super.x;
}
} Which on class A extends B {
constructor(...args) {
super(...args);
_foo.add(this);
}
}
var _foo2 = function _foo2() {
let A;
_get(_getPrototypeOf(A.prototype), "x", this);
}; |
👌👌 updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I've renamed the PR title so that it's clear what it does in the changelog.
super.*
…#11994