private void convertAsyncGenerator ( NodeTraversal t , Node originalFunction ) { checkNotNull ( originalFunction ) ; checkState ( originalFunction . isAsyncGeneratorFunction ( ) ) ; Node asyncGeneratorWrapperRef = astFactory . createAsyncGeneratorWrapperReference ( originalFunction . getJSType ( ) , t . getScope ( ) ) ; Node innerFunction = astFactory . createEmptyAsyncGeneratorWrapperArgument ( asyncGeneratorWrapperRef . getJSType ( ) ) ; Node innerBlock = originalFunction . getLastChild ( ) ; originalFunction . removeChild ( innerBlock ) ; innerFunction . replaceChild ( innerFunction . getLastChild ( ) , innerBlock ) ; // Body should be: // return new $jscomp.AsyncGeneratorWrapper((new function with original block here)()); Node outerBlock = astFactory . createBlock ( astFactory . createReturn ( astFactory . createNewNode ( asyncGeneratorWrapperRef , astFactory . createCall ( innerFunction ) ) ) ) ; originalFunction . addChildToBack ( outerBlock ) ; originalFunction . setIsAsyncFunction ( false ) ; originalFunction . setIsGeneratorFunction ( false ) ; originalFunction . useSourceInfoIfMissingFromForTree ( originalFunction ) ; // Both the inner and original functions should be marked as changed. compiler . reportChangeToChangeScope ( originalFunction ) ; compiler . reportChangeToChangeScope ( innerFunction ) ; }
Moves the body of an async generator function into a nested generator function and removes the async and generator props from the original function .