code: private static boolean consumesDanglingElse(Node n) {
      while (true) {
        switch (n.getToken()) {
          case IF:
            if (n.getChildCount() < 3) {
              return true;
            }
            // This IF node has no else clause.
            n = n.getLastChild();
            continue;
          case BLOCK:
            if (!n.hasOneChild()) {
              return false;
            }
            // This BLOCK has no curly braces.
            n = n.getLastChild();
            continue;
          case WITH:
          case WHILE:
          case FOR:
          case FOR_IN:
            n = n.getLastChild();
            continue;
          default:
            return false;
        }
      }
    }
docs: Does a statement consume a 'dangling else'? A statement consumes
  a 'dangling else' if an 'else' token following the statement
  would be considered by the parser to be part of the statement.