third_party/closure-compiler/src/src/com/google/javascript/jscomp/Es6RewriteModules.java
/**
     * Replace type name references. Change short names to fully qualified names
     * with namespace prefixes. Eg: {Foo} becomes {module$test.Foo}.
     */
Replace type name references. Change short names to fully qualified names
with namespace prefixes.
Replace type name references . Change short names to fully qualified names with namespace prefixes .
private void fixTypeNode(NodeTraversal t, Node typeNode) {
      if (typeNode.isString()) {
        Module thisModule = moduleMap.getModule(t.getInput().getPath());
        String name = typeNode.getString();
        List<String> splitted = Splitter.on('.').splitToList(name);
        String baseName = splitted.get(0);
        String rest = "";
        if (splitted.size() > 1) {
          rest = name.substring(baseName.length());
        }
        Var var = t.getScope().getVar(baseName);
        if (var != null && var.isGlobal()) {
          maybeSetNewName(
              t,
              typeNode,
              name,
              ModuleRenaming.getGlobalNameOfEsModuleLocalVariable(thisModule.metadata(), baseName)
                  + rest);
        } else if (var == null && thisModule.boundNames().containsKey(baseName)) {
          Binding binding = thisModule.boundNames().get(baseName);
          String globalName =
              ModuleRenaming.getGlobalNameForJsDoc(
                  moduleMap, binding, splitted.subList(1, splitted.size()));
          maybeSetNewName(t, typeNode, name, globalName);
          if (preprocessorSymbolTable != null) {
            Node onlyBaseName = Node.newString(baseName).useSourceInfoFrom(typeNode);
            onlyBaseName.setLength(baseName.length());
            maybeAddAliasToSymbolTable(onlyBaseName, t.getSourceName());
          }
        }
        typeNode.setOriginalName(name);
      }
      for (Node child = typeNode.getFirstChild(); child != null; child = child.getNext()) {
        fixTypeNode(t, child);
      }
    }
private void fixTypeNode ( NodeTraversal t , Node typeNode ) { if ( typeNode . isString ( ) ) { Module thisModule = moduleMap . getModule ( t . getInput ( ) . getPath ( ) ) ; String name = typeNode . getString ( ) ; List < String > splitted = Splitter . on ( '.' ) . splitToList ( name ) ; String baseName = splitted . get ( 0 ) ; String rest = "" ; if ( splitted . size ( ) > 1 ) { rest = name . substring ( baseName . length ( ) ) ; } Var var = t . getScope ( ) . getVar ( baseName ) ; if ( var != null && var . isGlobal ( ) ) { maybeSetNewName ( t , typeNode , name , ModuleRenaming . getGlobalNameOfEsModuleLocalVariable ( thisModule . metadata ( ) , baseName ) + rest ) ; } else if ( var == null && thisModule . boundNames ( ) . containsKey ( baseName ) ) { Binding binding = thisModule . boundNames ( ) . get ( baseName ) ; String globalName = ModuleRenaming . getGlobalNameForJsDoc ( moduleMap , binding , splitted . subList ( 1 , splitted . size ( ) ) ) ; maybeSetNewName ( t , typeNode , name , globalName ) ; if ( preprocessorSymbolTable != null ) { Node onlyBaseName = Node . newString ( baseName ) . useSourceInfoFrom ( typeNode ) ; onlyBaseName . setLength ( baseName . length ( ) ) ; maybeAddAliasToSymbolTable ( onlyBaseName , t . getSourceName ( ) ) ; } } typeNode . setOriginalName ( name ) ; } for ( Node child = typeNode . getFirstChild ( ) ; child != null ; child = child . getNext ( ) ) { fixTypeNode ( t , child ) ; } }
Replace type name references.
Replace type name references .
// Imports have been detached, so they won't show up in scope. Thus if we have a variable // not in scope that shares the name of an import it is the import. // Jsdoc type node is a single STRING node that spans the whole type. For example // STRING node "bar.Foo". ES6 import rewrite replaces only "module" // part of the type: "bar.Foo" => "module$full$path$bar$Foo". We have to record // "bar" as alias.