Only base async fn arity on non-default/non-rest params - fixes #4891 (#4901)

This commit is contained in:
Logan Smyth 2016-12-08 06:48:15 -08:00 committed by Henry Zhu
parent 39c92160f7
commit 80dfdd2a43
5 changed files with 54 additions and 2 deletions

View File

@ -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) {

View File

@ -6,7 +6,7 @@ let g = (() => {
yield 3;
});
return function g(_x) {
return function g() {
return _ref.apply(this, arguments);
};
})();

View File

@ -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) {}

View File

@ -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);
};
})();

View File

@ -0,0 +1,6 @@
{
"plugins": [
"transform-async-to-generator",
"external-helpers"
]
}