Async function to module method transform

This plugin allows Babel to transform async functions into a Bluebird coroutine.

示例

输入

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

输出

var Bluebird = require("bluebird");

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

安装

npm install --save-dev babel-plugin-transform-async-to-module-method

用法

通过 .babelrc(推荐)

.babelrc

未包含选项:

{
  "plugins": ["transform-async-to-module-method"]
}

包含选项:

{
  "plugins": [
    ["transform-async-to-module-method", {
      "module": "bluebird",
      "method": "coroutine"
    }]
  ]
}

通过 CLI

babel --plugins transform-async-to-module-method script.js

通过 Node API

require("babel-core").transform("code", {
  plugins: ["transform-async-to-module-method"]
});