Use the imports helper in async-to-module-method.
This commit is contained in:
@@ -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,
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user