Use the imports helper in async-to-module-method.
This commit is contained in:
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { coroutine as _coroutine } from "bluebird";
|
||||
var _coroutine = require("bluebird").coroutine;
|
||||
|
||||
_coroutine(function* () {
|
||||
yield foo();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { coroutine as _coroutine } from "bluebird";
|
||||
var _coroutine = require("bluebird").coroutine;
|
||||
|
||||
class Foo {
|
||||
foo() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { coroutine as _coroutine } from "bluebird";
|
||||
var _coroutine = require("bluebird").coroutine;
|
||||
|
||||
var foo = (() => {
|
||||
var _ref = _coroutine(function* () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { coroutine as _coroutine } from "bluebird";
|
||||
var _coroutine = require("bluebird").coroutine;
|
||||
|
||||
var foo = (() => {
|
||||
var _ref = _coroutine(function* () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { coroutine as _coroutine } from "bluebird";
|
||||
var _coroutine = require("bluebird").coroutine;
|
||||
|
||||
let foo = (() => {
|
||||
var _ref = _coroutine(function* () {
|
||||
|
||||
Reference in New Issue
Block a user