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 056606da3a..a7600e413a 100644 --- a/packages/babel-helper-remap-async-to-generator/src/index.js +++ b/packages/babel-helper-remap-async-to-generator/src/index.js @@ -122,7 +122,18 @@ function plainFunction(path: NodePath, callId: Object) { NAME: asyncFnId, REF: path.scope.generateUidIdentifier("ref"), FUNCTION: built, - PARAMS: node.params.map(() => path.scope.generateUidIdentifier("x")) + PARAMS: node.params.reduce((acc, param) => { + acc.done = acc.done || !t.isIdentifier(param); + + if (!acc.done) { + acc.params.push(path.scope.generateUidIdentifier("x")); + } + + return acc; + }, { + params: [], + done: false, + }).params, }).expression; if (isDeclaration) { diff --git a/packages/babel-plugin-transform-async-generator-functions/test/fixtures/nested/async-in-params/expected.js b/packages/babel-plugin-transform-async-generator-functions/test/fixtures/nested/async-in-params/expected.js index 4ad05ddcfa..bd04572e8a 100644 --- a/packages/babel-plugin-transform-async-generator-functions/test/fixtures/nested/async-in-params/expected.js +++ b/packages/babel-plugin-transform-async-generator-functions/test/fixtures/nested/async-in-params/expected.js @@ -6,7 +6,7 @@ let g = (() => { yield 3; }); - return function g(_x) { + return function g() { return _ref.apply(this, arguments); }; })(); diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/function-arity/actual.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/function-arity/actual.js new file mode 100644 index 0000000000..492289af70 --- /dev/null +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/function-arity/actual.js @@ -0,0 +1,4 @@ +async function one(a, b = 1) {} +async function two(a, b, ...c) {} +async function three(a, b = 1, c, d = 3) {} +async function four(a, b = 1, c, ...d) {} \ No newline at end of file diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/function-arity/expected.js b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/function-arity/expected.js new file mode 100644 index 0000000000..1db5d28058 --- /dev/null +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/function-arity/expected.js @@ -0,0 +1,31 @@ +let one = (() => { + var _ref = babelHelpers.asyncToGenerator(function* (a, b = 1) {}); + + return function one(_x) { + return _ref.apply(this, arguments); + }; +})(); + +let two = (() => { + var _ref2 = babelHelpers.asyncToGenerator(function* (a, b, ...c) {}); + + return function two(_x2, _x3) { + return _ref2.apply(this, arguments); + }; +})(); + +let three = (() => { + var _ref3 = babelHelpers.asyncToGenerator(function* (a, b = 1, c, d = 3) {}); + + return function three(_x4) { + return _ref3.apply(this, arguments); + }; +})(); + +let four = (() => { + var _ref4 = babelHelpers.asyncToGenerator(function* (a, b = 1, c, ...d) {}); + + return function four(_x5) { + return _ref4.apply(this, arguments); + }; +})(); \ No newline at end of file diff --git a/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/function-arity/options.json b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/function-arity/options.json new file mode 100644 index 0000000000..2373e1598f --- /dev/null +++ b/packages/babel-plugin-transform-async-to-generator/test/fixtures/async-to-generator/function-arity/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "transform-async-to-generator", + "external-helpers" + ] +} \ No newline at end of file