ast-types icon indicating copy to clipboard operation
ast-types copied to clipboard

Async ArrowFunctionExpression?

Open tmartensen opened this issue 7 years ago • 3 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 ... }

tmartensen avatar Apr 24 '18 15:04 tmartensen

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 avatar Apr 24 '18 16:04 tmartensen

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

tmartensen avatar Apr 25 '18 18:04 tmartensen

thanks

arrowFunc.callee.async = true

actually

caub avatar Jul 22 '19 21:07 caub