When parse5 parses an HTML document with `parse`, it injects missing root
elements (html, head and body) if they are missing.  This function removes
these from the AST if they have no location info, so it requires that
the `parse5.parse` be used with the `locationInfo` option of `true`.
function removeFakeRootElements(ast) {
  var injectedNodes = queryAll(
    ast,
    AND(function(node) {
      return !node.__location;
    }, hasMatchingTagName(/^(html|head|body)$/i)),
    undefined,
    // Don't descend past 3 levels 'document > html > head|body'
    function(node) {
      return node.parentNode && node.parentNode.parentNode ? undefined : node.childNodes;
    },
  );
  injectedNodes.reverse().forEach(removeNodeSaveChildren);
}