code: public static String getStringValue(Node n) {
      // TODO(user): regex literals as well.
      switch (n.getToken()) {
        case STRING:
        case STRING_KEY:
          return n.getString();
  
        case TEMPLATELIT:
          // Only convert a template literal if all its expressions can be converted.
          String string = "";
          for (Node child = n.getFirstChild(); child != null; child = child.getNext()) {
            Node expression = child;
            if (child.isTemplateLitSub()) {
              expression = child.getFirstChild();
            }
            String expressionString = getStringValue(expression);
            if (expressionString == null) {
              // Cannot convert.
              return null;
            }
            string = string + expressionString;
          }
          return string;
  
        case TEMPLATELIT_STRING:
          return n.getCookedString();
  
        case NAME:
          String name = n.getString();
          if ("undefined".equals(name)
              || "Infinity".equals(name)
              || "NaN".equals(name)) {
            return name;
          }
          break;
  
        case NUMBER:
          return DToA.numberToString(n.getDouble());
  
        case FALSE:
          return "false";
  
        case TRUE:
          return "true";
  
        case NULL:
          return "null";
  
        case VOID:
          return "undefined";
  
        case NOT:
          TernaryValue child = getPureBooleanValue(n.getFirstChild());
          if (child != TernaryValue.UNKNOWN) {
            return child.toBoolean(true) ? "false" : "true"; // reversed.
          }
          break;
  
        case ARRAYLIT:
          return arrayToString(n);
  
        case OBJECTLIT:
          return "[object Object]";
        default:
          break;
      }
      return null;
    }
docs: Gets the value of a node as a String, or null if it cannot be converted.
  When it returns a non-null String, this method effectively emulates the
  <code>String()</code> JavaScript cast function.