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 3 commits
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,9 @@ class Foo extends function () {} {
};

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

Choose a reason for hiding this comment

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

It takes an array.

Copy link
Contributor Author

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.

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

(function () {
_supercall(345);
Expand Down Expand Up @@ -115,9 +115,9 @@ describe("arrow function conversion", () => {
(function () {
_this;
});
_this = super();
super();
this;
() => _this = super();
() => super();
() => this;
`,
{ methodName: "constructor", extend: true },
Expand All @@ -144,9 +144,9 @@ describe("arrow function conversion", () => {

_this;
}).bind(_arrowCheckId);
_this = super();
super();
this;
() => _this = super();
() => super();
() => this;
`,
{
Expand Down