Calculate the correct arity for async functions with destructuring - fixes #4977 (#4978)

This commit is contained in:
Logan Smyth 2016-12-08 18:51:24 -08:00 committed by Henry Zhu
parent d597678def
commit 5aa87aab8d
3 changed files with 20 additions and 2 deletions

View File

@ -123,7 +123,7 @@ function plainFunction(path: NodePath, callId: Object) {
REF: path.scope.generateUidIdentifier("ref"),
FUNCTION: built,
PARAMS: node.params.reduce((acc, param) => {
acc.done = acc.done || !t.isIdentifier(param);
acc.done = acc.done || t.isAssignmentPattern(param) || t.isRestElement(param);
if (!acc.done) {
acc.params.push(path.scope.generateUidIdentifier("x"));

View File

@ -1,4 +1,6 @@
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) {}
async function four(a, b = 1, c, ...d) {}
async function five(a, {b}){}
async function six(a, {b} = {}){}

View File

@ -28,4 +28,20 @@ let four = (() => {
return function four(_x5) {
return _ref4.apply(this, arguments);
};
})();
let five = (() => {
var _ref5 = babelHelpers.asyncToGenerator(function* (a, { b }) {});
return function five(_x6, _x7) {
return _ref5.apply(this, arguments);
};
})();
let six = (() => {
var _ref6 = babelHelpers.asyncToGenerator(function* (a, { b } = {}) {});
return function six(_x8) {
return _ref6.apply(this, arguments);
};
})();