private Node transform(JsNameRef x) {
   Node n;
   JsName name = x.getName();
   boolean isExternal = name == null || !name.isObfuscatable();
   if (x.getQualifier() != null) {
     n = IR.getprop(transform(x.getQualifier()), transformNameAsString(x.getShortIdent(), x));
     if (isExternal) {
       this.externalProperties.add(x.getShortIdent());
     }
   } else {
     n = transformName(x.getShortIdent(), x);
     if (isExternal) {
       this.externalVars.add(x.getShortIdent());
     } else if (name.getEnclosing() == program.getScope()) {
       this.globalVars.add(x.getShortIdent());
     }
   }
   applyOriginalName(n, x);
   return applySourceInfo(n, x);
 }
Esempio n. 2
0
  @Override
  protected void visit(JsScope scope) {
    // Visit children.
    for (JsScope child : scope.getChildren()) {
      visit(child);
    }

    // Visit all my idents.
    for (JsName name : scope.getAllNames()) {
      if (!referenced.contains(name)) {
        // Don't allocate idents for non-referenced names.
        continue;
      }

      if (!name.isObfuscatable()) {
        // Unobfuscatable names become themselves.
        name.setShortIdent(name.getIdent());
        continue;
      }

      String fullIdent = name.getIdent();
      // Fixes package-info.java classes.
      fullIdent = fullIdent.replace("-", "_");
      if (!isLegal(fullIdent)) {
        String checkIdent;
        for (int i = 0; true; ++i) {
          checkIdent = fullIdent + "_" + i;
          if (isLegal(checkIdent)) {
            break;
          }
        }
        name.setShortIdent(checkIdent);
      } else {
        // set each name's short ident to its full ident
        name.setShortIdent(fullIdent);
      }
    }
  }