code: private void flattenReferencesTo(Name n, String alias) {
      String originalName = n.getFullName();
      for (Ref r : n.getRefs()) {
        if (r == n.getDeclaration()) {
          // Declarations are handled separately.
          continue;
        }
        Node rParent = r.getNode().getParent();
        // There are two cases when we shouldn't flatten a reference:
        // 1) Object literal keys, because duplicate keys show up as refs.
        // 2) References inside a complex assign. (a = x.y = 0). These are
        //    called TWIN references, because they show up twice in the
        //    reference list. Only collapse the set, not the alias.
        if (!NodeUtil.mayBeObjectLitKey(r.getNode()) && (r.getTwin() == null || r.isSet())) {
          flattenNameRef(alias, r.getNode(), rParent, originalName);
        } else if (r.getNode().isStringKey() && r.getNode().getParent().isObjectPattern()) {
          Node newNode = IR.name(alias).srcref(r.getNode());
          NodeUtil.copyNameAnnotations(r.getNode(), newNode);
          DestructuringGlobalNameExtractor.reassignDestructringLvalue(
              r.getNode(), newNode, null, r, compiler);
        }
      }
  
      // Flatten all occurrences of a name as a prefix of its subnames. For
      // example, if {@code n} corresponds to the name "a.b", then "a.b" will be
      // replaced with "a$b" in all occurrences of "a.b.c", "a.b.c.d", etc.
      if (n.props != null) {
        for (Name p : n.props) {
          flattenPrefixes(alias, p, 1);
        }
      }
    }
docs: Flattens all references to a collapsible property of a global name except
  its initial definition.
  
  @param n A global property name (e.g. "a.b" or "a.b.c.d")
  @param alias The flattened name (e.g. "a$b" or "a$b$c$d")