From 7d646b034c944b1b4fbf678bde9d17faf966ec2d Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Mon, 3 Dec 2018 16:35:11 -0700 Subject: [PATCH] Feedback from nicolo-ribaudo --- .../fixtures/arrow-functions/this/output.js | 5 +---- .../babel-traverse/src/path/conversion.js | 3 ++- .../babel-traverse/test/arrow-transform.js | 22 ++++--------------- 3 files changed, 7 insertions(+), 23 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 f85f02a77f4b..824dc5706ceb 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,12 +15,9 @@ class Foo extends function () {} { }; if (true) { - var _temp; - - console.log((_temp = super(), _this2 = this, _temp), foo()); + console.log(super(), foo()); } else { 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 b144f3b8ec0d..89821f1d6928 100644 --- a/packages/babel-traverse/src/path/conversion.js +++ b/packages/babel-traverse/src/path/conversion.js @@ -461,7 +461,8 @@ function getThisBinding(thisEnvFn, inConstructor) { if (supers.has(child.node)) return; supers.add(child.node); - child.insertAfter( + child.replaceWithMultiple( + child.node, t.assignmentExpression( "=", t.identifier(thisBinding), diff --git a/packages/babel-traverse/test/arrow-transform.js b/packages/babel-traverse/test/arrow-transform.js index 6201de7134a2..97675e8d95fe 100644 --- a/packages/babel-traverse/test/arrow-transform.js +++ b/packages/babel-traverse/test/arrow-transform.js @@ -82,12 +82,8 @@ describe("arrow function conversion", () => { () => this; `, ` - var _supercall = (..._args) => { - var _temp; - - return _temp = super(..._args), _this = this, _temp; - }, - _this; + var _supercall = (..._args) => super(..._args), + _this; (function () { _supercall(345); @@ -120,13 +116,8 @@ describe("arrow function conversion", () => { _this; }); super(); - _this = this; this; - () => { - var _temp; - - return _temp = super(), _this = this, _temp; - } + () => super(); () => this; `, { methodName: "constructor", extend: true }, @@ -154,13 +145,8 @@ describe("arrow function conversion", () => { _this; }).bind(_arrowCheckId); super(); - _this = this; this; - () => { - var _temp; - - return _temp = super(), _this = this, _temp; - } + () => super(); () => this; `, {