All files / utils traverse-up-dom.js

100% Statements 20/20
100% Branches 12/12
100% Functions 1/1
100% Lines 20/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 212x 2x 2x 2x 2x 2x 21x 21x 52x 36x 52x 1x 1x 1x 52x 21x 21x 34x 30x 21x  
/**
 * Traverse up in the document DOM closest element by passing shadow DOM
 * @param {Element} targetElement - first element to yield from the generator
 * @yields {Element} one element for each subsequent ancestor
 */
export function * traverseUpDom (targetElement) {
  let el = targetElement
  while (el != null) {
    yield el
    const { parentNode, parentElement } = el
    if (parentNode instanceof ShadowRoot) {
      el = parentNode.host
      continue
    }
    if (parentNode instanceof Document || parentElement == null) {
      return
    }
    el = parentElement
  }
}