From db3a43869cb81076179288db3839fd77f294756a Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Sun, 6 Mar 2016 16:58:54 -0800 Subject: [PATCH] Remap across arrow function boundaries - fixes T7108 --- .../internal-plugins/shadow-functions.js | 4 +- .../test/fixtures/regression/T7108/actual.js | 33 ++++++++++ .../fixtures/regression/T7108/expected.js | 61 +++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7108/actual.js create mode 100644 packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7108/expected.js diff --git a/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js b/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js index 13e5e955ac..76e137002c 100644 --- a/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js +++ b/packages/babel-core/src/transformation/internal-plugins/shadow-functions.js @@ -19,7 +19,7 @@ function shouldShadow(path, shadowPath) { if (path.is("_forceShadow")) { return true; } else { - return shadowPath && !shadowPath.isArrowFunctionExpression(); + return shadowPath; } } @@ -39,7 +39,7 @@ function remap(path, key, create) { if (path.isProgram()) { return true; - } else if (path.isFunction()) { + } else if (path.isFunction() && !path.isArrowFunctionExpression()) { if (shadowFunction) { return path === shadowFunction || path.node === shadowFunction.node; } else { diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7108/actual.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7108/actual.js new file mode 100644 index 0000000000..68075431ac --- /dev/null +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7108/actual.js @@ -0,0 +1,33 @@ +class Test{ + static async method1() { + console.log(this); + + setTimeout(async () => { + console.log(this); + }); + } + + static async method2() { + console.log(this); + + setTimeout(async (arg) => { + console.log(this); + }); + } + + async method1() { + console.log(this); + + setTimeout(async () => { + console.log(this); + }); + } + + async method2() { + console.log(this); + + setTimeout(async (arg) => { + console.log(this); + }); + } +} diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7108/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7108/expected.js new file mode 100644 index 0000000000..f3fc39332c --- /dev/null +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T7108/expected.js @@ -0,0 +1,61 @@ +class Test { + static method1() { + var _this = this; + + return babelHelpers.asyncToGenerator(function* () { + console.log(_this); + + setTimeout(babelHelpers.asyncToGenerator(function* () { + console.log(_this); + })); + })(); + } + + static method2() { + var _this2 = this; + + return babelHelpers.asyncToGenerator(function* () { + console.log(_this2); + + setTimeout((() => { + var ref = babelHelpers.asyncToGenerator(function* (arg) { + console.log(_this2); + }), + _this = _this2; + return function (_x) { + return ref.apply(_this, arguments); + }; + })()); + })(); + } + + method1() { + var _this3 = this; + + return babelHelpers.asyncToGenerator(function* () { + console.log(_this3); + + setTimeout(babelHelpers.asyncToGenerator(function* () { + console.log(_this3); + })); + })(); + } + + method2() { + var _this4 = this; + + return babelHelpers.asyncToGenerator(function* () { + console.log(_this4); + + setTimeout((() => { + var ref = babelHelpers.asyncToGenerator(function* (arg) { + console.log(_this4); + }), + _this = _this4; + return function (_x2) { + return ref.apply(_this, arguments); + }; + })()); + })(); + } +}