Class RewriteAsyncFunctions

java.lang.Object
com.google.javascript.jscomp.RewriteAsyncFunctions
All Implemented Interfaces:
CompilerPass, NodeTraversal.Callback

public final class RewriteAsyncFunctions extends Object implements NodeTraversal.Callback, CompilerPass
Converts async functions to valid ES6 generator functions code.

This pass must run before the passes that transpile let declarations, arrow functions, and generators.

An async function, foo(a, b), will be rewritten as:


 function foo(a, b) {
   let $jscomp$async$this = this;
   let $jscomp$async$arguments = arguments;
   let $jscomp$async$super$get$x = () => super.x;
   return $jscomp.asyncExecutePromiseGeneratorFunction(
       function* () {
         // original body of foo() with:
         // - await (x) replaced with yield (x)
         // - arguments replaced with $jscomp$async$arguments
         // - this replaced with $jscomp$async$this
         // - super.x replaced with $jscomp$async$super$get$x()
         // - super.x(5) replaced with $jscomp$async$super$get$x().call($jscomp$async$this, 5)
       });
 }