/**
 * Get DOM representation for an element.
 *
 * @param {HTMLElement} element
 * @param {null|undefined|HTMLElement} nodeContext
 * @returns {string|null}
 */
export function getExpression(element, nodeContext = null) {
  let paths = []

  const isNodeContext = () => {
    if (!nodeContext) {
      return true
    }
    return nodeContext !== element
  }

  while ((element.nodeType === window.Node.ELEMENT_NODE) && isNodeContext()) {
    let index = 0

    for (let sibling = element.previousSibling; sibling; sibling = sibling.previousSibling) {
      if (sibling.nodeType === window.Node.DOCUMENT_TYPE_NODE) {
        continue
      }
      if (sibling.nodeName === element.nodeName) {
        ++index
      }
    }

    let tagName = element.nodeName.toLowerCase()
    let pathIndex = `[${index + 1}]`

    paths.unshift(tagName + pathIndex)
    element = element.parentNode
  }

  if (paths.length === 0) {
    return null
  }
  return nodeContext ? paths.join('/') : `/${paths.join('/')}`
}

/**
 * Get an element from expression
 *
 * @param {string} expression
 * @param {HTMLElement} nodeContext
 * @returns {HTMLElement|null}
 */
export function getElement(expression, nodeContext = null) {
  if (!nodeContext) {
    nodeContext = document.body
  }

  const evaluated = document.evaluate(expression, nodeContext, null, window.XPathResult.ANY_TYPE)
  return evaluated.iterateNext()
}

@@ -1,16 +1,292 @@
+/**%0A * XPath Utilities%0A * @type %7Bobject%7D%0A */%0Aexport const util = %7B%0A%0A  /**%0A   * Is current element part of an SVG element%0A   *%0A   * @param   %7BHTMLElement%7D element%0A   * @returns %7Bboolean%7D%0A   */%0A  isSVG: function(element) %7B%0A    return element instanceof window.SVGElement%0A  %7D%0A%7D%0A%0A
 /**%0A * Get DOM r

Add `xpath.util.isSVG`. Can be stubbed in tests.