Skip to content

Instantly share code, notes, and snippets.

@pgherveou
Created October 5, 2016 16:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pgherveou/bbc001a1cebe11d734fffc1f4f2f9dee to your computer and use it in GitHub Desktop.
Save pgherveou/bbc001a1cebe11d734fffc1f4f2f9dee to your computer and use it in GitHub Desktop.
convert co/yield to to async/await
// 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