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
Not depending on return value of super(). Fixes #9020. #9060
Conversation
@@ -461,8 +461,12 @@ function getThisBinding(thisEnvFn, inConstructor) { | |||
if (supers.has(child.node)) return; | |||
supers.add(child.node); | |||
|
|||
child.replaceWith( | |||
t.assignmentExpression("=", t.identifier(thisBinding), child.node), | |||
child.insertAfter( |
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.
See this comment for why I made this change
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9541/ |
console.log(_this2 = super(), foo()); | ||
var _temp; | ||
|
||
console.log((_temp = super(), _this2 = this, _temp), foo()); |
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.
This doesn't fully fix the issue: in edge it would log undefined, foo()
instead of this, foo()
.
You need to use replaceWithMultiple("super call", "this assignment")
, because insertAfter
keep the initial completion value (undefined
in edge).
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.
👍 good catch - @nicolo-ribaudo I just updated it to do what you said. Let me know if I misunderstood.
fb57c17
to
7d646b0
Compare
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.
I would have expected many more tests to change 🤔
@@ -461,8 +461,13 @@ function getThisBinding(thisEnvFn, inConstructor) { | |||
if (supers.has(child.node)) return; | |||
supers.add(child.node); | |||
|
|||
child.replaceWith( | |||
t.assignmentExpression("=", t.identifier(thisBinding), child.node), | |||
child.replaceWithMultiple( |
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.
It takes an array.
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.
@nicolo-ribaudo oops! I just fixed that. I don't fully understand the expected output in some of the tests, so I didn't catch that the second argument was being ignored.
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.
I'm surpiprised that only two tests changed, but LGTM 👍
Yeah I was surprised that there weren't more tests affected, too. Are you the one who will merge this @nicolo-ribaudo? Or is that someone else? |
I think the reason that there aren't more tests affected is that, if i understand the code correctly, this only affects |
Is there a risk this fix break #2279 ? |
It shouldn't; this PR doesn't touch transpilation of |
Hey, any chance this could be released? Thanks 🙂 |
See #9020 and this comment where @nicolo-ribaudo suggested the change that I implemented here. This is my first contribution to babel and I'm not very familiar with the codebase -- I welcome any feedback. I consider this to be a best effort implementation, since I probably am missing some things or don't fully understand the implications of my code changes.