benjamn / ast-types

Esprima-compatible implementation of the Mozilla JS Parser API
MIT License
1.14k stars 198 forks source link

Async ArrowFunctionExpression? #264

Open tmartensen opened 6 years ago

tmartensen commented 6 years ago

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 ... }

tmartensen commented 6 years ago

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!

tmartensen commented 6 years ago

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
caub commented 5 years ago

thanks

arrowFunc.callee.async = true

actually