helper-remap-async-to-generator: account for ObjectMethod - fixes #2838

This commit is contained in:
Henry Zhu
2015-11-05 23:57:53 -05:00
parent 5508f4de56
commit 042af348bc
3 changed files with 17 additions and 3 deletions

View File

@@ -0,0 +1,6 @@
let obj = {
a: 123,
async foo(bar) {
return await baz(bar);
}
}

View File

@@ -0,0 +1,8 @@
let obj = {
a: 123,
foo(bar) {
return babelHelpers.asyncToGenerator(function* () {
return yield baz(bar);
})();
}
};

View File

@@ -24,7 +24,7 @@ let awaitVisitor = {
}
};
function classMethod(path: NodePath, callId: Object) {
function classOrObjectMethod(path: NodePath, callId: Object) {
let node = path.node;
let body = node.body;
@@ -99,8 +99,8 @@ export default function (path: NodePath, callId: Object) {
path.traverse(awaitVisitor);
if (path.isClassMethod()) {
return classMethod(path, callId);
if (path.isClassMethod() || path.isObjectMethod()) {
return classOrObjectMethod(path, callId);
} else {
return plainFunction(path, callId);
}