private boolean isEligibleDefinitionFunction ( Node definitionFunction ) { checkArgument ( definitionFunction . isFunction ( ) , definitionFunction ) ; if ( definitionFunction . isArrowFunction ( ) ) { return false ; } for ( Node ancestor = definitionFunction . getParent ( ) ; ancestor != null ; ancestor = ancestor . getParent ( ) ) { // The definition must be made exactly once. (i.e. not in a loop, conditional, or function) if ( isScopingOrBranchingConstruct ( ancestor ) ) { return false ; } // TODO(nickreid): Support this so long as the definition doesn't reference the name. // We can't allow this in general because references to the local name: // - won't be rewritten correctly // - won't be the same across multiple definitions, even if they are node-wise identical. if ( ancestor . isClass ( ) && localNameIsDeclaredByClass ( ancestor ) ) { return false ; } } if ( NodeUtil . containsType ( definitionFunction , Token . SUPER ) ) { // TODO(b/120452418): Remove this when we have a rewrite for `super`. We punted initially due // to complexity. return false ; } if ( NodeUtil . doesFunctionReferenceOwnArgumentsObject ( definitionFunction ) ) { // Functions that access "arguments" are not eligible since rewriting changes the structure of // the function params. return false ; } return true ; }
Determines if a method definition function is eligible for rewrite as a global function .