diff --git a/packages/babel-helper-remap-async-to-generator/src/index.js b/packages/babel-helper-remap-async-to-generator/src/index.js index f22ab48e35..c1aa6d34a2 100644 --- a/packages/babel-helper-remap-async-to-generator/src/index.js +++ b/packages/babel-helper-remap-async-to-generator/src/index.js @@ -6,7 +6,7 @@ import template from "babel-template"; import * as t from "babel-types"; let buildWrapper = template(` - (function () { + (() => { var ref = FUNCTION; return function NAME(PARAMS) { return ref.apply(this, arguments); @@ -15,7 +15,7 @@ let buildWrapper = template(` `); let namedBuildWrapper = template(` - (function () { + (() => { var ref = FUNCTION; function NAME(PARAMS) { return ref.apply(this, arguments); @@ -24,15 +24,6 @@ let namedBuildWrapper = template(` }) `); -let arrowBuildWrapper = template(` - (() => { - var ref = FUNCTION, _this = this; - return function(PARAMS) { - return ref.apply(_this, arguments); - }; - }) -`); - let awaitVisitor = { ArrowFunctionExpression(path) { if (!path.node.async) { @@ -69,19 +60,12 @@ function plainFunction(path: NodePath, callId: Object) { if (path.isArrowFunctionExpression()) { path.arrowFunctionToShadowed(); - wrapper = arrowBuildWrapper; } else if (!isDeclaration && asyncFnId) { wrapper = namedBuildWrapper; } node.async = false; node.generator = true; - // Either the wrapped generator is invoked with `.apply(this, arguments)` or it has no params, - // so it should capture `arguments` - if (node.shadow) { - // node.shadow may be `true` or an object - node.shadow = Object.assign({}, node.shadow, { arguments: false }); - } node.id = null; diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/async-arrow-in-method/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/async-arrow-in-method/expected.js index 3d421469f5..a307b98c83 100644 --- a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/async-arrow-in-method/expected.js +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/async-arrow-in-method/expected.js @@ -1,19 +1,17 @@ -let TestClass = { - name: "John Doe", - - testMethodFailure() { - return new Promise((() => { - var _this2 = this; - - var ref = babelHelpers.asyncToGenerator(function* (resolve) { - console.log(_this2); - setTimeout(resolve, 1000); - }), - _this = this; - - return function (_x) { - return ref.apply(_this, arguments); - }; - })()); - } -}; +let TestClass = { + name: "John Doe", + + testMethodFailure() { + var _this = this; + + return new Promise((() => { + var ref = babelHelpers.asyncToGenerator(function* (resolve) { + console.log(_this); + setTimeout(resolve, 1000); + }); + return function (_x) { + return ref.apply(this, arguments); + }; + })()); + } +}; diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/deeply-nested-asyncs/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/deeply-nested-asyncs/expected.js index b32aae134c..691a0b30d1 100644 --- a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/deeply-nested-asyncs/expected.js +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/deeply-nested-asyncs/expected.js @@ -1,27 +1,24 @@ -let s = function () { +let s = (() => { var ref = babelHelpers.asyncToGenerator(function* (x) { - var _this2 = this; + var _this = this; let t = (() => { var ref = babelHelpers.asyncToGenerator(function* (y, a) { let r = (() => { var ref = babelHelpers.asyncToGenerator(function* (z, b) { yield z; - return _this2.x; - }), - _this = _this2; - + return _this.x; + }); return function r(_x4, _x5) { - return ref.apply(_this, arguments); + return ref.apply(this, arguments); }; })(); yield r(); - return _this2.g(r); - }), - _this = this; + return _this.g(r); + }); return function t(_x2, _x3) { - return ref.apply(_this, arguments); + return ref.apply(this, arguments); }; })(); @@ -31,4 +28,4 @@ let s = function () { return function s(_x) { return ref.apply(this, arguments); }; -}(); +})(); diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/expression/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/expression/expected.js index e3c7d2218f..baff50e27f 100644 --- a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/expression/expected.js +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/expression/expected.js @@ -1,8 +1,8 @@ -var foo = function () { +var foo = (() => { var ref = babelHelpers.asyncToGenerator(function* () { var wat = yield bar(); }); return function foo() { return ref.apply(this, arguments); }; -}(); +})(); diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/named-expression/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/named-expression/expected.js index c6282326b3..fabf097a50 100644 --- a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/named-expression/expected.js +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/named-expression/expected.js @@ -1,4 +1,4 @@ -var foo = function () { +var foo = (() => { var ref = babelHelpers.asyncToGenerator(function* () { console.log(bar); }); @@ -8,4 +8,4 @@ var foo = function () { } return bar; -}(); +})(); diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/parameters/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/parameters/expected.js index 2cbaf5139e..bee7bb6870 100644 --- a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/parameters/expected.js +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/parameters/expected.js @@ -1,6 +1,6 @@ -let foo = function () { +let foo = (() => { var ref = babelHelpers.asyncToGenerator(function* (bar) {}); return function foo(_x) { return ref.apply(this, arguments); }; -}(); +})(); diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/statement/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/statement/expected.js index 51140320d4..4fa3965734 100644 --- a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/statement/expected.js +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/statement/expected.js @@ -1,8 +1,8 @@ -let foo = function () { +let foo = (() => { var ref = babelHelpers.asyncToGenerator(function* () { var wat = yield bar(); }); return function foo() { return ref.apply(this, arguments); }; -}(); +})(); diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/import-and-export/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/import-and-export/expected.js index 7ea795d5ca..5ac84b7eb0 100644 --- a/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/import-and-export/expected.js +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/import-and-export/expected.js @@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", { }); exports.foo = undefined; -let foo = exports.foo = function () { +let foo = exports.foo = (() => { var ref = babelHelpers.asyncToGenerator(function* () {}); return function foo() { return ref.apply(this, arguments); }; -}(); +})(); var _bar = require('bar'); diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/lone-export/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/lone-export/expected.js index 3f1072c7e3..99b7a1da10 100644 --- a/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/lone-export/expected.js +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/export-async/lone-export/expected.js @@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); -let foo = exports.foo = function () { +let foo = exports.foo = (() => { var ref = babelHelpers.asyncToGenerator(function* () {}); return function foo() { return ref.apply(this, arguments); }; -}(); +})(); 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 index f3fc39332c..a2dd94f127 100644 --- 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 @@ -20,10 +20,9 @@ class Test { setTimeout((() => { var ref = babelHelpers.asyncToGenerator(function* (arg) { console.log(_this2); - }), - _this = _this2; + }); return function (_x) { - return ref.apply(_this, arguments); + return ref.apply(this, arguments); }; })()); })(); @@ -50,10 +49,9 @@ class Test { setTimeout((() => { var ref = babelHelpers.asyncToGenerator(function* (arg) { console.log(_this4); - }), - _this = _this4; + }); return function (_x2) { - return ref.apply(_this, arguments); + return ref.apply(this, arguments); }; })()); })(); diff --git a/packages/babel-plugin-transform-async-to-module-method/test/fixtures/bluebird-coroutines/expression/expected.js b/packages/babel-plugin-transform-async-to-module-method/test/fixtures/bluebird-coroutines/expression/expected.js index 1d7bf3bba5..d4567b0dea 100644 --- a/packages/babel-plugin-transform-async-to-module-method/test/fixtures/bluebird-coroutines/expression/expected.js +++ b/packages/babel-plugin-transform-async-to-module-method/test/fixtures/bluebird-coroutines/expression/expected.js @@ -1,5 +1,5 @@ import { coroutine as _coroutine } from "bluebird"; -var foo = function () { +var foo = (() => { var ref = _coroutine(function* () { var wat = yield bar(); }); @@ -7,4 +7,4 @@ var foo = function () { return function foo() { return ref.apply(this, arguments); }; -}(); +})(); diff --git a/packages/babel-plugin-transform-async-to-module-method/test/fixtures/bluebird-coroutines/named-expression/expected.js b/packages/babel-plugin-transform-async-to-module-method/test/fixtures/bluebird-coroutines/named-expression/expected.js index 082562347d..91a3c61229 100644 --- a/packages/babel-plugin-transform-async-to-module-method/test/fixtures/bluebird-coroutines/named-expression/expected.js +++ b/packages/babel-plugin-transform-async-to-module-method/test/fixtures/bluebird-coroutines/named-expression/expected.js @@ -1,5 +1,5 @@ import { coroutine as _coroutine } from "bluebird"; -var foo = function () { +var foo = (() => { var ref = _coroutine(function* () { console.log(bar); }); @@ -9,4 +9,4 @@ var foo = function () { } return bar; -}(); +})(); diff --git a/packages/babel-plugin-transform-async-to-module-method/test/fixtures/bluebird-coroutines/statement/expected.js b/packages/babel-plugin-transform-async-to-module-method/test/fixtures/bluebird-coroutines/statement/expected.js index ef7b97d56b..72167461b0 100644 --- a/packages/babel-plugin-transform-async-to-module-method/test/fixtures/bluebird-coroutines/statement/expected.js +++ b/packages/babel-plugin-transform-async-to-module-method/test/fixtures/bluebird-coroutines/statement/expected.js @@ -1,6 +1,6 @@ import { coroutine as _coroutine } from "bluebird"; -let foo = function () { +let foo = (() => { var ref = _coroutine(function* () { var wat = yield bar(); }); @@ -8,4 +8,4 @@ let foo = function () { return function foo() { return ref.apply(this, arguments); }; -}(); +})();