Class RewriteAsyncFunctions

  • All Implemented Interfaces:
    CompilerPass, NodeTraversal.Callback

    public final class RewriteAsyncFunctions
    extends java.lang.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)
           });
     }
     
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void process​(Node externs, Node root)
      Process the JS with root node root.
      boolean shouldTraverse​(NodeTraversal nodeTraversal, Node n, Node parent)
      Visits a node in preorder (before its children) and decides whether the node and its children should be traversed.
      void visit​(NodeTraversal t, Node n, Node parent)
      Visits a node in postorder (after its children).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait