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

Not depending on return value of super(). Fixes #9020. #9060

Merged
merged 4 commits into from Dec 4, 2018
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
Expand Up @@ -15,9 +15,12 @@ class Foo extends function () {} {
};

if (true) {
console.log(_this2 = super(), foo());
var _temp;

console.log((_temp = super(), _this2 = this, _temp), foo());
Copy link
Member

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).

Copy link
Contributor Author

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.

} else {
_this2 = super();
super();
_this2 = this;
console.log(foo());
}
}
Expand Down
8 changes: 6 additions & 2 deletions packages/babel-traverse/src/path/conversion.js
Expand Up @@ -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(
Copy link
Contributor Author

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

t.assignmentExpression(
"=",
t.identifier(thisBinding),
t.identifier("this"),
),
);
},
});
Expand Down
24 changes: 19 additions & 5 deletions packages/babel-traverse/test/arrow-transform.js
Expand Up @@ -82,7 +82,11 @@ describe("arrow function conversion", () => {
() => this;
`,
`
var _supercall = (..._args) => _this = super(..._args),
var _supercall = (..._args) => {
var _temp;

return _temp = super(..._args), _this = this, _temp;
},
_this;

(function () {
Expand Down Expand Up @@ -115,9 +119,14 @@ describe("arrow function conversion", () => {
(function () {
_this;
});
_this = super();
super();
_this = this;
this;
() => _this = super();
() => {
var _temp;

return _temp = super(), _this = this, _temp;
}
() => this;
`,
{ methodName: "constructor", extend: true },
Expand All @@ -144,9 +153,14 @@ describe("arrow function conversion", () => {

_this;
}).bind(_arrowCheckId);
_this = super();
super();
_this = this;
this;
() => _this = super();
() => {
var _temp;

return _temp = super(), _this = this, _temp;
}
() => this;
`,
{
Expand Down