private boolean checkForBadModuleReference ( Name name , Ref ref ) { JSModuleGraph moduleGraph = compiler . getModuleGraph ( ) ; if ( name . getGlobalSets ( ) == 0 || ref . type == Ref . Type . SET_FROM_GLOBAL ) { // Back off if either 1) this name was never set, or 2) this reference /is/ a set. return false ; } if ( name . getGlobalSets ( ) == 1 ) { // there is only one global set - it should be set as name.declaration // just look at that declaration instead of iterating through every single reference. Ref declaration = checkNotNull ( name . getDeclaration ( ) ) ; return ! isSetFromPrecedingModule ( ref , declaration , moduleGraph ) ; } // there are multiple sets, so check if any of them happens in this module or a module earlier // in the dependency chain. for ( Ref set : name . getRefs ( ) ) { if ( isSetFromPrecedingModule ( ref , set , moduleGraph ) ) { return false ; } } return true ; }
Returns true if this name is potentially referenced before being defined in a different module