From f3a3925afb21b53b381c2f908b4a639ee019edc9 Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Wed, 21 Nov 2018 18:55:27 -0700 Subject: [PATCH] Not depending on return value of super(). Fixes #9020. --- .../fixtures/arrow-functions/this/output.js | 7 ++++-- .../babel-traverse/src/path/conversion.js | 8 +++++-- .../babel-traverse/test/arrow-transform.js | 24 +++++++++++++++---- 3 files changed, 30 insertions(+), 9 deletions(-) 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..f85f02a77f4b 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,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()); } } diff --git a/packages/babel-traverse/src/path/conversion.js b/packages/babel-traverse/src/path/conversion.js index cf45cc320b2b..b144f3b8ec0d 100644 --- a/packages/babel-traverse/src/path/conversion.js +++ b/packages/babel-traverse/src/path/conversion.js @@ -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"), + ), ); }, }); diff --git a/packages/babel-traverse/test/arrow-transform.js b/packages/babel-traverse/test/arrow-transform.js index d74ca8f71196..6201de7134a2 100644 --- a/packages/babel-traverse/test/arrow-transform.js +++ b/packages/babel-traverse/test/arrow-transform.js @@ -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 () { @@ -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 }, @@ -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; `, {