Merge pull request #2798 from amasad/fix-2782
Fix recursion in async-to-generator transforms
This commit is contained in:
commit
1796b1926c
@ -1,8 +1,8 @@
|
||||
var foo = (function () {
|
||||
var ref = babelHelpers.asyncToGenerator(function* bar() {
|
||||
var ref = babelHelpers.asyncToGenerator(function* () {
|
||||
console.log(bar);
|
||||
});
|
||||
return function foo() {
|
||||
return function bar() {
|
||||
return ref.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
let foo = (function () {
|
||||
var ref = babelHelpers.asyncToGenerator(function* foo(bar) {});
|
||||
var ref = babelHelpers.asyncToGenerator(function* (bar) {});
|
||||
return function foo(_x) {
|
||||
return ref.apply(this, arguments);
|
||||
};
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
let foo = (function () {
|
||||
var ref = babelHelpers.asyncToGenerator(function* foo() {
|
||||
var ref = babelHelpers.asyncToGenerator(function* () {
|
||||
var wat = yield bar();
|
||||
});
|
||||
return function foo() {
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { coroutine as _coroutine } from "bluebird";
|
||||
var foo = (function () {
|
||||
var ref = _coroutine(function* bar() {
|
||||
var ref = _coroutine(function* () {
|
||||
console.log(bar);
|
||||
});
|
||||
|
||||
return function foo() {
|
||||
return function bar() {
|
||||
return ref.apply(this, arguments);
|
||||
};
|
||||
})();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { coroutine as _coroutine } from "bluebird";
|
||||
|
||||
let foo = (function () {
|
||||
var ref = _coroutine(function* foo() {
|
||||
var ref = _coroutine(function* () {
|
||||
var wat = yield bar();
|
||||
});
|
||||
|
||||
|
||||
@ -50,6 +50,9 @@ function plainFunction(path: NodePath, callId: Object) {
|
||||
node.async = false;
|
||||
node.generator = true;
|
||||
|
||||
let asyncFnId = node.id;
|
||||
node.id = null;
|
||||
|
||||
let built = t.callExpression(callId, [node]);
|
||||
let container = buildWrapper({
|
||||
FUNCTION: built,
|
||||
@ -61,25 +64,24 @@ function plainFunction(path: NodePath, callId: Object) {
|
||||
if (path.isFunctionDeclaration()) {
|
||||
let declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(
|
||||
t.identifier(node.id.name),
|
||||
t.identifier(asyncFnId.name),
|
||||
t.callExpression(container, [])
|
||||
)
|
||||
]);
|
||||
declar._blockHoist = true;
|
||||
|
||||
nameFunction({
|
||||
node: retFunction,
|
||||
parent: declar.declarations[0],
|
||||
scope: path.scope
|
||||
});
|
||||
|
||||
retFunction.id = asyncFnId;
|
||||
path.replaceWith(declar);
|
||||
} else {
|
||||
nameFunction({
|
||||
node: retFunction,
|
||||
parent: path.parent,
|
||||
scope: path.scope
|
||||
});
|
||||
if (asyncFnId && asyncFnId.name) {
|
||||
retFunction.id = asyncFnId;
|
||||
} else {
|
||||
nameFunction({
|
||||
node: retFunction,
|
||||
parent: path.parent,
|
||||
scope: path.scope
|
||||
});
|
||||
}
|
||||
|
||||
if (retFunction.id || node.params.length) {
|
||||
// we have an inferred function id or params so we need this wrapper
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user