From e33ad7d2fb4f1c45b461e5258a9c054351241f21 Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Tue, 3 Nov 2015 14:58:31 -0800 Subject: [PATCH] Convert arrow functions when remaping to generator. Fixes #2789 --- .../bluebird-coroutines/arrow-function/actual.js | 1 + .../bluebird-coroutines/arrow-function/expected.js | 4 ++++ packages/babel-helper-remap-async-to-generator/src/index.js | 4 ++++ 3 files changed, 9 insertions(+) create mode 100644 packages/babel-core/test/fixtures/transformation/bluebird-coroutines/arrow-function/actual.js create mode 100644 packages/babel-core/test/fixtures/transformation/bluebird-coroutines/arrow-function/expected.js diff --git a/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/arrow-function/actual.js b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/arrow-function/actual.js new file mode 100644 index 0000000000..215205fa31 --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/arrow-function/actual.js @@ -0,0 +1 @@ +(async () => { await foo(); })() diff --git a/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/arrow-function/expected.js b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/arrow-function/expected.js new file mode 100644 index 0000000000..570c1e15bc --- /dev/null +++ b/packages/babel-core/test/fixtures/transformation/bluebird-coroutines/arrow-function/expected.js @@ -0,0 +1,4 @@ +import { coroutine as _coroutine } from "bluebird"; +_coroutine(function* () { + yield foo(); +})(); 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 1e84a4fec7..e6c96dd9b1 100644 --- a/packages/babel-helper-remap-async-to-generator/src/index.js +++ b/packages/babel-helper-remap-async-to-generator/src/index.js @@ -43,6 +43,10 @@ function classMethod(path: NodePath, callId: Object) { function plainFunction(path: NodePath, callId: Object) { let node = path.node; + if (path.isArrowFunctionExpression()) { + path.arrowFunctionToShadowed(); + } + node.async = false; node.generator = true;