Created
October 5, 2016 16:12
-
-
Save pgherveou/bbc001a1cebe11d734fffc1f4f2f9dee to your computer and use it in GitHub Desktop.
convert co/yield to to async/await
This file contains 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
// http://astexplorer.net/#/BICnPGGYdU/4 | |
export default function ({types: t}) { | |
return { | |
visitor: { | |
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