Use the imports helper in async-to-module-method.

This commit is contained in:
Logan Smyth
2017-09-19 11:29:49 -07:00
parent ec9754bc40
commit 11715cb7af
7 changed files with 19 additions and 7 deletions

View File

@@ -10,6 +10,7 @@
],
"dependencies": {
"babel-helper-remap-async-to-generator": "7.0.0-beta.2",
"babel-helper-module-imports": "7.0.0-beta.2",
"babel-plugin-syntax-async-functions": "7.0.0-beta.0",
"babel-types": "7.0.0-beta.2"
},

View File

@@ -1,7 +1,9 @@
import remapAsyncToGenerator from "babel-helper-remap-async-to-generator";
import syntaxAsyncFunctions from "babel-plugin-syntax-async-functions";
export default function() {
import { addNamed } from "babel-helper-module-imports";
export default function({ types: t }) {
return {
inherits: syntaxAsyncFunctions,
@@ -9,8 +11,17 @@ export default function() {
Function(path, state) {
if (!path.node.async || path.node.generator) return;
const { module, method } = state.opts;
let wrapAsync = state.methodWrapper;
if (wrapAsync) {
wrapAsync = t.cloneDeep(wrapAsync);
} else {
wrapAsync = state.methodWrapper = addNamed(path, method, module);
}
remapAsyncToGenerator(path, state.file, {
wrapAsync: state.addImport(state.opts.module, state.opts.method),
wrapAsync,
});
},
},

View File

@@ -1,4 +1,4 @@
import { coroutine as _coroutine } from "bluebird";
var _coroutine = require("bluebird").coroutine;
_coroutine(function* () {
yield foo();

View File

@@ -1,4 +1,4 @@
import { coroutine as _coroutine } from "bluebird";
var _coroutine = require("bluebird").coroutine;
class Foo {
foo() {

View File

@@ -1,4 +1,4 @@
import { coroutine as _coroutine } from "bluebird";
var _coroutine = require("bluebird").coroutine;
var foo = (() => {
var _ref = _coroutine(function* () {

View File

@@ -1,4 +1,4 @@
import { coroutine as _coroutine } from "bluebird";
var _coroutine = require("bluebird").coroutine;
var foo = (() => {
var _ref = _coroutine(function* () {

View File

@@ -1,4 +1,4 @@
import { coroutine as _coroutine } from "bluebird";
var _coroutine = require("bluebird").coroutine;
let foo = (() => {
var _ref = _coroutine(function* () {