-
-
Save hex-ci/a70065f4acb0a65fdced8a45c7069e77 to your computer and use it in GitHub Desktop.
convert co/yield to to async/await
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://astexplorer.net/#/gist/48d24982fceb3f258cc2dcd764fe8e38/937f48fc25443224a08bb20774a7d8868052770c | |
export default function ({types: t}) { | |
return { | |
visitor: { | |
ObjectMethod(path) { | |
if (path.node.generator) { | |
path.node.async = true | |
path.node.generator = false | |
} | |
}, | |
ClassMethod(path) { | |
if (path.node.generator) { | |
path.node.async = true | |
path.node.generator = false | |
} | |
}, | |
FunctionExpression(path) { | |
if (path.node.generator) { | |
path.node.async = true | |
path.node.generator = false | |
} | |
}, | |
FunctionDeclaration(path) { | |
if (path.node.generator) { | |
path.node.async = true | |
path.node.generator = false | |
} | |
}, | |
YieldExpression: function(path) { | |
let argument = path.node.argument | |
path.replaceWith(t.awaitExpression(argument), false) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment