ScopedName getClosureNamespaceTypeFromCall ( Node googRequire ) { if ( moduleMap == null ) { // TODO(b/124919359): make sure all tests have generated a ModuleMap return null ; } String moduleId = googRequire . getSecondChild ( ) . getString ( ) ; Module module = moduleMap . getClosureModule ( moduleId ) ; if ( module == null ) { return null ; } switch ( module . metadata ( ) . moduleType ( ) ) { case GOOG_PROVIDE : // Expect this to be a global variable Node provide = module . metadata ( ) . rootNode ( ) ; if ( provide != null && provide . isScript ( ) ) { return ScopedName . of ( moduleId , provide . getGrandparent ( ) ) ; } else { // Unknown module requires default to 'goog provides', but we don't want to type them. return null ; } case GOOG_MODULE : case LEGACY_GOOG_MODULE : // TODO(b/124919359): Fix getGoogModuleScopeRoot to never return null. Node scopeRoot = getGoogModuleScopeRoot ( module ) ; return scopeRoot != null ? ScopedName . of ( "exports" , scopeRoot ) : null ; case ES6_MODULE : throw new IllegalStateException ( "Type checking ES modules not yet supported" ) ; case COMMON_JS : throw new IllegalStateException ( "Type checking CommonJs modules not yet supported" ) ; case SCRIPT : throw new IllegalStateException ( "Cannot import a name from a SCRIPT" ) ; } throw new AssertionError ( ) ; }
Attempts to look up the type of a Closure namespace from a require call