From 4a4c7ffe948e5c6902c61fc34a4d4580a0034578 Mon Sep 17 00:00:00 2001 From: Gajus Kuizinas Date: Fri, 28 Apr 2017 14:42:11 +0100 Subject: [PATCH] fix: apply the current scope when invoking a function --- src/babel/index.js | 10 ++++++++-- .../fixtures/class-properties/block-body/expected.js | 2 +- .../class-properties/default-params/expected.js | 2 +- .../class-properties/destructured-params/expected.js | 2 +- .../class-properties/expression-body/expected.js | 2 +- .../same-name-as-class-method/expected.js | 2 +- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/babel/index.js b/src/babel/index.js index 72cfc45b0..77954e531 100644 --- a/src/babel/index.js +++ b/src/babel/index.js @@ -19,8 +19,14 @@ var UNUSED = (function () { const buildNewClassProperty = (t, classPropertyName, newMethodName, isAsync) => { let returnExpression = t.callExpression( - t.memberExpression(t.thisExpression(), newMethodName), - [t.spreadElement(t.identifier('params'))] + t.memberExpression( + t.memberExpression(t.thisExpression(), newMethodName), + t.identifier('apply') + ), + [ + t.thisExpression(), + t.identifier('params'), + ] ); if (isAsync) { diff --git a/test/babel/fixtures/class-properties/block-body/expected.js b/test/babel/fixtures/class-properties/block-body/expected.js index fa7ebdee5..d70823531 100644 --- a/test/babel/fixtures/class-properties/block-body/expected.js +++ b/test/babel/fixtures/class-properties/block-body/expected.js @@ -1,6 +1,6 @@ class Foo { constructor() { - this.bar = (...params) => this.__bar__REACT_HOT_LOADER__(...params); + this.bar = (...params) => this.__bar__REACT_HOT_LOADER__.apply(this, params); } __bar__REACT_HOT_LOADER__(a, b) { diff --git a/test/babel/fixtures/class-properties/default-params/expected.js b/test/babel/fixtures/class-properties/default-params/expected.js index 879a42eab..27ae61963 100644 --- a/test/babel/fixtures/class-properties/default-params/expected.js +++ b/test/babel/fixtures/class-properties/default-params/expected.js @@ -1,6 +1,6 @@ class Foo { constructor() { - this.bar = (...params) => this.__bar__REACT_HOT_LOADER__(...params); + this.bar = (...params) => this.__bar__REACT_HOT_LOADER__.apply(this, params); } __bar__REACT_HOT_LOADER__(a = "foo") { diff --git a/test/babel/fixtures/class-properties/destructured-params/expected.js b/test/babel/fixtures/class-properties/destructured-params/expected.js index 1cf23da22..e2ae12d82 100644 --- a/test/babel/fixtures/class-properties/destructured-params/expected.js +++ b/test/babel/fixtures/class-properties/destructured-params/expected.js @@ -1,6 +1,6 @@ class Foo { constructor() { - this.bar = (...params) => this.__bar__REACT_HOT_LOADER__(...params); + this.bar = (...params) => this.__bar__REACT_HOT_LOADER__.apply(this, params); } __bar__REACT_HOT_LOADER__({ a }, { b }) { diff --git a/test/babel/fixtures/class-properties/expression-body/expected.js b/test/babel/fixtures/class-properties/expression-body/expected.js index ced1724a1..b01c6c8c8 100644 --- a/test/babel/fixtures/class-properties/expression-body/expected.js +++ b/test/babel/fixtures/class-properties/expression-body/expected.js @@ -1,6 +1,6 @@ class Foo { constructor() { - this.onClick = (...params) => this.__onClick__REACT_HOT_LOADER__(...params); + this.onClick = (...params) => this.__onClick__REACT_HOT_LOADER__.apply(this, params); } __onClick__REACT_HOT_LOADER__(e) { diff --git a/test/babel/fixtures/class-properties/same-name-as-class-method/expected.js b/test/babel/fixtures/class-properties/same-name-as-class-method/expected.js index 9bcc53586..2c3b50a6c 100644 --- a/test/babel/fixtures/class-properties/same-name-as-class-method/expected.js +++ b/test/babel/fixtures/class-properties/same-name-as-class-method/expected.js @@ -1,6 +1,6 @@ class Foo { constructor() { - this.bar = (...params) => this.__bar__REACT_HOT_LOADER__(...params); + this.bar = (...params) => this.__bar__REACT_HOT_LOADER__.apply(this, params); } __bar__REACT_HOT_LOADER__(a, b) {