export function serialize()

in spec/frontend/clean_html_element_serializer.js [38:69]


export function serialize(received, config, indentation, depth, refs, printer) {
  const clone = received.cloneNode(true);
  visited.add(clone);

  // Remove comment nodes
  const iterator = document.createNodeIterator(
    clone,
    // eslint-disable-next-line no-bitwise
    NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT,
  );
  const ignorableNodes = [];

  for (let currentNode = iterator.nextNode(); currentNode; currentNode = iterator.nextNode()) {
    if (isIgnorable(currentNode)) {
      ignorableNodes.push(currentNode);
    } else {
      if (currentNode instanceof Element && !currentNode.tagName.includes('-')) {
        ATTRIBUTES_TO_REMOVE.forEach((attr) => currentNode.removeAttribute(attr));
        BOOLEAN_ATTRIBUTES.forEach((attr) => {
          if (currentNode.hasAttribute(attr) && currentNode.getAttribute(attr) === attr) {
            currentNode.setAttribute(attr, '');
          }
        });
      }
      visited.add(currentNode);
    }
  }

  ignorableNodes.forEach((x) => x.remove());

  return printer(clone, config, indentation, depth, refs);
}