From 042af348bc62b134f6e92c2e9d681f3fc18926f7 Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Thu, 5 Nov 2015 23:57:53 -0500 Subject: [PATCH] helper-remap-async-to-generator: account for ObjectMethod - fixes #2838 --- .../async-to-generator/object-method/actual.js | 6 ++++++ .../async-to-generator/object-method/expected.js | 8 ++++++++ .../babel-helper-remap-async-to-generator/src/index.js | 6 +++--- 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 packages/babel-core/test/fixtures/transformation/async-to-generator/object-method/actual.js create mode 100644 packages/babel-core/test/fixtures/transformation/async-to-generator/object-method/expected.js 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); }