Skip to content

Commit

Permalink
Not depending on return value of super(). Fixes babel#9020.
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldenning committed Nov 22, 2018
1 parent 61c1c77 commit f3a3925
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
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());
} 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(
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

0 comments on commit f3a3925

Please sign in to comment.