Class RewriteAsyncIteration

  • All Implemented Interfaces:
    CompilerPass, NodeTraversal.Callback

    public final class RewriteAsyncIteration
    extends java.lang.Object
    implements NodeTraversal.Callback, CompilerPass
    Converts async generator functions into a function returning a new $jscomp.AsyncGenWrapper around the original block and awaits/yields converted to yields of ActionRecords.
    
     async function* foo() {
       let res = await myPromise;
       yield res + 1;
     }
     

    becomes (prefixes trimmed for clarity)

    
     function foo() {
       return new $jscomp.AsyncGeneratorWrapper((function*(){
         let res = yield new $ActionRecord($ActionEnum.AWAIT_VALUE, myPromise);
         yield new $ActionRecord($ActionEnum.YIELD_VALUE, res + 1);
       })());
     }
     
    • 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