code: @Override
    public void afterExitScope(NodeTraversal t, ReferenceMap referenceMap) {
      Node scopeRoot = t.getScopeRoot();
      if (scopeRoot.isBlock() && scopeRoot.getParent().isFunction()) {
        boolean changed = false;
        for (Var v : t.getScope().getVarIterable()) {
          ReferenceCollection references = referenceMap.getReferences(v);
          Reference declaration = null;
          Reference assign = null;
          for (Reference r : references) {
            if (r.isVarDeclaration()
                && NodeUtil.isStatement(r.getNode().getParent())
                && !r.isInitializingDeclaration()) {
              declaration = r;
            } else if (assign == null
                && r.isSimpleAssignmentToName()
                && r.getScope().getClosestHoistScope().equals(t.getScope())) {
              assign = r;
            }
          }
          if (declaration != null && assign != null) {
            Node lhs = assign.getNode();
            Node assignNode = lhs.getParent();
            if (assignNode.getParent().isExprResult()) {
              Node rhs = lhs.getNext();
              assignNode
                  .getGrandparent()
                  .replaceChild(assignNode.getParent(), IR.var(lhs.detach(), rhs.detach()));
  
              Node var = declaration.getNode().getParent();
              checkState(var.isVar(), var);
              NodeUtil.removeChild(var, declaration.getNode());
  
              changed = true;
            }
          }
        }
  
        if (changed) {
          t.reportCodeChange();
        }
      }
    }
docs: Implements step 3 (inlining the var keyword).