codemod icon indicating copy to clipboard operation
codemod copied to clipboard

Async codemod introduces improper awaits and does not create async anonymous function contexts

Open kliph-gladly opened this issue 2 years ago • 0 comments

Running the async codemod on the following code

const foo = function() {
  mySyncFunctionDoesNotReturnAPromiseOrEvenExist();
};

produces

const foo = function() {
  await mySyncFunctionDoesNotReturnAPromiseOrEvenExist();
};

This is syntactically incorrect for two reasons.

  • The outer function context foo is not async so it doesn't make sense to use await within it.
  • The function called in the inner scope mySyncFunctionDoesNotReturnAPromiseOrEvenExist does not return a Promise, so it doesn't make sense to use await.

kliph-gladly avatar Feb 23 '23 19:02 kliph-gladly