private void maybeRemoveUnusedTrailingParameters ( Node argList , Scope fparamScope ) { Node lastArg ; while ( ( lastArg = argList . getLastChild ( ) ) != null ) { Node lValue = lastArg ; if ( lastArg . isDefaultValue ( ) ) { lValue = lastArg . getFirstChild ( ) ; if ( NodeUtil . mayHaveSideEffects ( lastArg . getLastChild ( ) , compiler ) ) { break ; } } if ( lValue . isRest ( ) ) { lValue = lValue . getFirstChild ( ) ; } if ( lValue . isDestructuringPattern ( ) ) { if ( lValue . hasChildren ( ) ) { // TODO(johnlenz): handle the case where there are no assignments. break ; } else { // Remove empty destructuring patterns and their associated object literal assignment // if it exists and if the right hand side does not have side effects. Note, a // destructuring pattern with a "leftover" property key as in {a:{}} is not considered // empty in this case! NodeUtil . deleteNode ( lastArg , compiler ) ; continue ; } } VarInfo varInfo = getVarInfo ( getVarForNameNode ( lValue , fparamScope ) ) ; if ( varInfo . isRemovable ( ) ) { NodeUtil . deleteNode ( lastArg , compiler ) ; } else { break ; } } }
Strip as many unreferenced args off the end of the function declaration as possible . We start from the end of the function declaration because removing parameters from the middle of the param list could mess up the interpretation of parameters being sent over by any function calls .