code: static Double getNumberValue(Node n) {
      switch (n.getToken()) {
        case TRUE:
          return 1.0;
  
        case FALSE:
        case NULL:
          return 0.0;
  
        case NUMBER:
          return n.getDouble();
  
        case VOID:
          if (mayHaveSideEffects(n.getFirstChild())) {
            return null;
          } else {
            return Double.NaN;
          }
  
        case NAME:
          // Check for known constants
          String name = n.getString();
          if (name.equals("undefined")) {
            return Double.NaN;
          }
          if (name.equals("NaN")) {
            return Double.NaN;
          }
          if (name.equals("Infinity")) {
            return Double.POSITIVE_INFINITY;
          }
          return null;
  
        case NEG:
          if (n.hasOneChild() && n.getFirstChild().isName()
              && n.getFirstChild().getString().equals("Infinity")) {
            return Double.NEGATIVE_INFINITY;
          }
          return null;
  
        case NOT:
          TernaryValue child = getPureBooleanValue(n.getFirstChild());
          if (child != TernaryValue.UNKNOWN) {
            return child.toBoolean(true) ? 0.0 : 1.0; // reversed.
          }
          break;
  
        case TEMPLATELIT:
          String string = getStringValue(n);
          if (string == null) {
            return null;
          }
          return getStringNumberValue(string);
  
        case STRING:
          return getStringNumberValue(n.getString());
  
        case ARRAYLIT:
        case OBJECTLIT:
          String value = getStringValue(n);
          return value != null ? getStringNumberValue(value) : null;
        default:
          break;
      }
  
      return null;
    }
docs: Gets the value of a node as a Number, or null if it cannot be converted.
  When it returns a non-null Double, this method effectively emulates the
  <code>Number()</code> JavaScript cast function.
  
  @param n The node.
  @return The value of a node as a Number, or null if it cannot be converted.