babel/packages/babel-plugin-transform-async-to-generator
Diogo Franco 0f60d42fdf
Avoid adding #__PURE__ annotation to .bind(this)() expressions (#7043)
* Avoid adding #__PURE__ annotation to .bind(this)() expressions

Fixes the #__PURE__ annotation getting added to (async () => {})() IIFEs when the arrow function transform is running with spec: true.

* Return false instead of undefined

* Fix indentation in json files

* Add one more case to the async-iife fixtures
2017-12-28 17:02:54 +09:00
..
2017-03-25 21:46:16 -04:00
2017-12-25 14:04:08 -05:00

@babel/plugin-transform-async-to-generator

Turn async functions into ES2015 generators

In Babel 7, transform-async-to-module-method was merged into this plugin

Example

In

async function foo() {
  await bar();
}

Out

var _asyncToGenerator = function (fn) {
  ...
};
var foo = _asyncToGenerator(function* () {
  yield bar();
});

Out with options

Turn async functions into a Bluebird coroutine

var Bluebird = require("bluebird");

var foo = Bluebird.coroutine(function* () {
  yield bar();
});

Installation

npm install --save-dev @babel/plugin-transform-async-to-generator

Usage

.babelrc

Without options:

{
  "plugins": ["@babel/plugin-transform-async-to-generator"]
}

With options:

{
  "plugins": [
    ["@babel/plugin-transform-async-to-generator", {
      "module": "bluebird",
      "method": "coroutine"
    }]
  ]
}

Via CLI

babel --plugins @babel/plugin-transform-async-to-generator script.js

Via Node API

require("@babel/core").transform("code", {
  plugins: ["@babel/plugin-transform-async-to-generator"]
});

References