private void decomposeInIIFE ( NodeTraversal t , Node classNode ) { // converts // `class X extends something {}` // to // `(function() { return class X extends something {}; })()` Node functionBody = IR . block ( ) ; Node function = IR . function ( IR . name ( "" ) , IR . paramList ( ) , functionBody ) ; Node call = NodeUtil . newCallNode ( function ) ; classNode . replaceWith ( call ) ; functionBody . addChildToBack ( IR . returnNode ( classNode ) ) ; call . useSourceInfoIfMissingFromForTree ( classNode ) ; // NOTE: extractExtends() will end up reporting the change for the new function, so we only // need to report the change to the enclosing scope t . reportCodeChange ( call ) ; // Now do the extends expression extraction within the IIFE extractExtends ( t , classNode ) ; }
When a class is used in an expressions where adding an alias as the previous statement might change execution order of a side - effect causing statement wrap the class in an IIFE so that decomposition can happen safely .