if root children have only on child we can flatten this
482387
function flattenTree(root) {
  let newChildren = [];
  root.children.forEach(child => {
    const commonParent = getDeepMoreThenOneChild(child);
    if (commonParent.children.length === 0) {
      newChildren.push(commonParent);
    } else {
      newChildren = newChildren.concat(commonParent.children);
    }
  });
  root.children = newChildren;
}
706398
private void findHomogeneousLeaves(AreaImpl root)
    {
        if (root.getChildCount() > 1)
            findSuperAreas(root, 1);
        for (int i = 0; i < root.getChildCount(); i++)
            findHomogeneousLeaves((AreaImpl) root.getChildAt(i));
    }
230671
function _getRoot(transform) {
  return function() {
    var parent = transform.parent;
    return parent === undefined ? transform : parent.root;
  }
}
1258864
def add_node_parents(root: ast.AST) -> None:
    
    for node in ast.walk(root):
        for child in ast.iter_child_nodes(node):
            child.parent = node
1217027
private void flattenSimpleStubDeclaration(Name name, String alias) {
    Ref ref = Iterables.getOnlyElement(name.getRefs());
    Node nameNode = NodeUtil.newName(compiler, alias, ref.getNode(), name.getFullName());
    Node varNode = IR.var(nameNode).useSourceInfoIfMissingFrom(nameNode);

    checkState(ref.getNode().getParent().isExprResult());
    Node parent = ref.getNode().getParent();
    Node grandparent = parent.getParent();
    grandparent.replaceChild(parent, varNode);
    compiler.reportChangeToEnclosingScope(varNode);
  }
1254854
def flatten_all_paths(self, group_filter=lambda x: True,
                          path_filter=lambda x: True,
                          path_conversions=CONVERSIONS):
        """"""
        return flatten_all_paths(self.tree.getroot(), group_filter,
                                 path_filter, path_conversions)
1156700
function() {
        var child;
        var root = this.vectorRoot;
        if (root) {
            while (child = root.firstChild) {
                root.removeChild(child);
            }
        }
        root = this.textRoot;
        if (root) {
            while (child = root.firstChild) {
                root.removeChild(child);
            }
        }
        if (this.indexer) {
            this.indexer.clear();
        }
    }
997099
def descendants(self, cl=None, noduplicates=True):
        
        if not cl:
            cl = self
        if cl.children():
            bag = []
            for x in cl.children():
                if x.uri != cl.uri:  # avoid circular relationships
                    bag += [x] + self.descendants(x, noduplicates)
                else:
                    bag += [x]
            # finally:
            if noduplicates:
                return remove_duplicates(bag)
            else:
                return bag
        else:
            return []
60965
function() {
        this.setChildren(this.get('inputs').concat(this.get('children') || []));

        var ancestor = this.get('parent.parent');
        if(ancestor) {
          ancestor.setChildren(this.get('outputs').concat(ancestor.get('children') || []));
        }
        this.set('_additionalsIncluded', true);
      }
727790
def mend(self, length):
        """"""
        if length == 0: raise Exception("Can't mend the root !")
        if length == 1: return
        self.children = OrderedDict((node.name, node) for node in self.get_level(length))
        for child in self.children.values(): child.parent = self
1331539
function ( level, depth ) {
            if ( level >= depth ) {
                return this;
            }
            if ( this.childrenCount() === 0 ) {
                return;
            }

            for ( var i = 0, n = this.childrenCount(); i < n; i++ ) {
                var leftmostDescendant = this.childAt( i ).leftMost( level + 1, depth );
                if ( leftmostDescendant ) {
                    return leftmostDescendant;
                }
            }
        }
175560
RBBINode flattenVariables() {
        if (fType == varRef) {
            RBBINode retNode  = fLeftChild.cloneTree();
            retNode.fRuleRoot = this.fRuleRoot;
            retNode.fChainIn  = this.fChainIn;
            return retNode;
        }

        if (fLeftChild != null) {
            fLeftChild = fLeftChild.flattenVariables();
            fLeftChild.fParent = this;
        }
        if (fRightChild != null) {
            fRightChild = fRightChild.flattenVariables();
            fRightChild.fParent = this;
        }
        return this;
    }
158521
private List<DefNode> flatten(DefNode node) {
        final List<DefNode> result = new ArrayList<>();
        result.add(node);
        return flatten(result, node.getChildren());
    }
1307843
function simplifyDOM(root, atEnd) {
    var doc = root.ownerDocument;
    var result = [];
    var leaving = true;

    function simplifyNode(node, top) {
      if (node.nodeType == 3) {
        var text = node.nodeValue = fixSpaces(node.nodeValue.replace(/[\r\u200b]/g, "").replace(/\n/g, " "));
        if (text.length) leaving = false;
        result.push(node);
      }
      else if (isBR(node) && node.childNodes.length == 0) {
        leaving = true;
        result.push(node);
      }
      else {
        forEach(node.childNodes, simplifyNode);
        if (!leaving && newlineElements.hasOwnProperty(node.nodeName.toUpperCase())) {
          leaving = true;
          if (!atEnd || !top)
            result.push(doc.createElement("BR"));
        }
      }
    }

    simplifyNode(root, true);
    return result;
  }
405423
def flattenPorts(root: LNode):
    
    for u in root.children:
        u.west = _flattenPortsSide(u.west)
        u.east = _flattenPortsSide(u.east)
        u.north = _flattenPortsSide(u.north)
        u.south = _flattenPortsSide(u.south)
1205322
def flatten(&merger)
      trees.reverse_each.reduce(Tree[]) do |result, tree|
        result.merge!(tree, &merger)
      end
    end
360690
@Override
  public final Iterable<T> children(final T root) {
    checkNotNull(root);
    return new FluentIterable<T>() {
      @Override
      public Iterator<T> iterator() {
        return new AbstractIterator<T>() {
          boolean doneLeft;
          boolean doneRight;

          @Override
          protected T computeNext() {
            if (!doneLeft) {
              doneLeft = true;
              Optional<T> left = leftChild(root);
              if (left.isPresent()) {
                return left.get();
              }
            }
            if (!doneRight) {
              doneRight = true;
              Optional<T> right = rightChild(root);
              if (right.isPresent()) {
                return right.get();
              }
            }
            return endOfData();
          }
        };
      }
    };
  }