diff --git a/packages/babel-plugin-transform-arrow-functions/test/fixtures/arrow-functions/this/output.js b/packages/babel-plugin-transform-arrow-functions/test/fixtures/arrow-functions/this/output.js index f13e5374e2bc..bc43aa41d838 100644 --- a/packages/babel-plugin-transform-arrow-functions/test/fixtures/arrow-functions/this/output.js +++ b/packages/babel-plugin-transform-arrow-functions/test/fixtures/arrow-functions/this/output.js @@ -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()); } } diff --git a/packages/babel-traverse/src/path/conversion.js b/packages/babel-traverse/src/path/conversion.js index cf45cc320b2b..cc1f1003a443 100644 --- a/packages/babel-traverse/src/path/conversion.js +++ b/packages/babel-traverse/src/path/conversion.js @@ -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"), + ), + ]); }, }); }); diff --git a/packages/babel-traverse/test/arrow-transform.js b/packages/babel-traverse/test/arrow-transform.js index d74ca8f71196..78b0fb19de11 100644 --- a/packages/babel-traverse/test/arrow-transform.js +++ b/packages/babel-traverse/test/arrow-transform.js @@ -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); @@ -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 }, @@ -144,9 +145,10 @@ describe("arrow function conversion", () => { _this; }).bind(_arrowCheckId); - _this = super(); + super(); + _this = this; this; - () => _this = super(); + () => (super(), _this = this); () => this; `, {