Node tryOptimizeArrayPattern ( Node pattern ) { checkArgument ( pattern . isArrayPattern ( ) , pattern ) ; for ( Node lastChild = pattern . getLastChild ( ) ; lastChild != null ; ) { if ( lastChild . isEmpty ( ) || isRemovableDestructuringTarget ( lastChild ) ) { Node prev = lastChild . getPrevious ( ) ; pattern . removeChild ( lastChild ) ; lastChild = prev ; reportChangeToEnclosingScope ( pattern ) ; } else { // don't remove any non-trailing empty nodes because that will change the ordering of the // other assignments // note that this case also covers array pattern rest, which must be the final element break ; } } return pattern ; }
Removes trailing EMPTY nodes and empty array patterns