Skip to content

Commit

Permalink
Not depending on return value of super(). Fixes #9020. (#9060)
Browse files Browse the repository at this point in the history
* Not depending on return value of super(). Fixes #9020.

* Feedback from nicolo-ribaudo

* Feedback -- fixing bad call to replaceWithMultiple
  • Loading branch information
joeldenning authored and nicolo-ribaudo committed Dec 4, 2018
1 parent 8b132c0 commit d305419
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Expand Up @@ -15,9 +15,10 @@ class Foo extends function () {} {
};

if (true) {
console.log(_this2 = super(), foo());
console.log((super(), _this2 = this), foo());
} else {
_this2 = super();
super();
_this2 = this;
console.log(foo());
}
}
Expand Down
11 changes: 8 additions & 3 deletions packages/babel-traverse/src/path/conversion.js
Expand Up @@ -461,9 +461,14 @@ 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([
child.node,
t.assignmentExpression(
"=",
t.identifier(thisBinding),
t.identifier("this"),
),
]);
},
});
});
Expand Down
14 changes: 8 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 = this),
_this;
(function () {
_supercall(345);
Expand Down Expand Up @@ -115,9 +115,10 @@ describe("arrow function conversion", () => {
(function () {
_this;
});
_this = super();
super();
_this = this;
this;
() => _this = super();
() => (super(), _this = this);
() => this;
`,
{ methodName: "constructor", extend: true },
Expand All @@ -144,9 +145,10 @@ describe("arrow function conversion", () => {
_this;
}).bind(_arrowCheckId);
_this = super();
super();
_this = this;
this;
() => _this = super();
() => (super(), _this = this);
() => this;
`,
{
Expand Down

0 comments on commit d305419

Please sign in to comment.