code: private void tryOptimizeConditionalAfterAssign(Node n) {
      Node next = n.getNext();
  
      // Look for patterns like the following and replace the if-condition with
      // a constant value so it can later be folded:
      //   var a = /a/;
      //   if (a) {foo(a)}
      // or
      //   a = 0;
      //   a ? foo(a) : c;
      // or
      //   a = 0;
      //   a || foo(a);
      // or
      //   a = 0;
      //   a && foo(a)
      //
      // TODO(johnlenz): This would be better handled by control-flow sensitive
      // constant propagation. As the other case that I want to handle is:
      //   i=0; for(;i<0;i++){}
      // as right now nothing facilitates removing a loop like that.
      // This is here simply to remove the cruft left behind goog.userAgent and
      // similar cases.
  
      if (isSimpleAssignment(n) && isConditionalStatement(next)) {
        Node lhsAssign = getSimpleAssignmentName(n);
  
        Node condition = getConditionalStatementCondition(next);
        if (lhsAssign.isName() && condition.isName()
            && lhsAssign.getString().equals(condition.getString())) {
          Node rhsAssign = getSimpleAssignmentValue(n);
          TernaryValue value = NodeUtil.getImpureBooleanValue(rhsAssign);
          if (value != TernaryValue.UNKNOWN) {
            Node replacementConditionNode =
                NodeUtil.booleanNode(value.toBoolean(true));
            condition.replaceWith(replacementConditionNode);
            reportChangeToEnclosingScope(replacementConditionNode);
          }
        }
      }
    }
docs: Attempt to replace the condition of if or hook immediately that is a
  reference to a name that is assigned immediately before.