benjamn / ast-types

Esprima-compatible implementation of the Mozilla JS Parser API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Async ArrowFunctionExpression?

tmartensen opened this issue · comments

Is it possible to create an async ArrowFunctionExpression? I'm using jscodeshift to modify some code, and I need to create a variable declaration with this signature:
const doSomethingAsync = async args => { await ... }

Ok, I can work around it by prefixing any args with async to the identifier i'm using. For example:

j.arrowFunctionExpression(
  [j.identifier("async args")],
  body
)

But that doesn't feel right. Any help/advice would be appreciated. Thanks!

Found another way to do it. It's easy to set the above code to a variable, and add async after the initialization:

const arrowFunc = j.arrowFunctionExpression(
  [j.identifier("args")],
  body
)
arrowFunc.async = true

thanks

arrowFunc.callee.async = true

actually