code: @Override
    public void visit(NodeTraversal t, Node n, Node parent) {
      if (topLevelStatementDraft != null) {
        if (n.equals(topLevelStatementDraft.statementNode)) {
          topLevelStatements.add(new TopLevelStatement(topLevelStatementDraft));
          topLevelStatementDraft = null;
        } else if (n.isName()) {
          String varName = n.getString();
          Var v = t.getScope().getVar(varName);
  
          if (v != null) {
            // Only global, non-exported names can be moved
            if (v.isGlobal() && !compiler.getCodingConvention().isExported(v.getName())) {
              if (varsByName.containsKey(varName)) {
                checkState(Objects.equals(varsByName.get(varName), v));
              } else {
                varsByName.put(varName, v);
              }
              Reference reference = new Reference(n, t, peek(blockStack));
              if (reference.getNode() == topLevelStatementDraft.declaredNameNode) {
                topLevelStatementDraft.declaredNameReference = reference;
              } else {
                topLevelStatementDraft.nonDeclarationReferences.add(reference);
              }
              addReferenceToCollection(v, reference);
            }
          }
        }
      }
      if (isBlockBoundary(n, parent)) {
        pop(blockStack);
      }
    }
docs: For each node, update the block stack and reference collection
  as appropriate.