diff --git a/packages/babel-core/test/fixtures/transformation/async-to-generator/object-method/actual.js b/packages/babel-core/test/fixtures/transformation/async-to-generator/object-method/actual.js new file mode 100644 index 0000000000..c6400ef2fa --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/async-to-generator/object-method/actual.js @@ -0,0 +1,6 @@ +let obj = { + a: 123, + async foo(bar) { + return await baz(bar); + } +} diff --git a/packages/babel-core/test/fixtures/transformation/async-to-generator/object-method/expected.js b/packages/babel-core/test/fixtures/transformation/async-to-generator/object-method/expected.js new file mode 100644 index 0000000000..7628e45eca --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/async-to-generator/object-method/expected.js @@ -0,0 +1,8 @@ +let obj = { + a: 123, + foo(bar) { + return babelHelpers.asyncToGenerator(function* () { + return yield baz(bar); + })(); + } +}; 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 453f4c52ad..8a08e58ec4 100644 --- a/packages/babel-helper-remap-async-to-generator/src/index.js +++ b/packages/babel-helper-remap-async-to-generator/src/index.js @@ -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); }