src/core/context/node.js
/**
   * Returns the closest available context node to the one specified. If the
   * `node` has the context node, it's returned unless `includeSelf` is set as
   * `false`.
   *
   * The DOM traversal goes at most as far as the root node (document,
   * shadow root, document fragment) or as far as the DOM tree allows. The
   * traversal follows the assigned shadow slots.
   *
   * Root nodes (document or shadow root) and AMP elements are auto-created
   * during the traversal.
   *
   * @param {Node} node The node from which to perform the search.
   * @param {boolean=} includeSelf Whether the specified node itself should
   * be included in the search. Defaults to `true`.
   * @return {?ContextNode<?>}
   */
Returns the closest available context node to the one specified.

The DOM traversal goes at most as far as the root node (document,
shadow root, document fragment) or as far as the DOM tree allows. The
traversal follows the assigned shadow slots.

Root nodes (document or shadow root) and AMP elements are auto-created
during the traversal.

@param {Node} node The node from which to perform the search.
@param {boolean=} includeSelf Whether the specified node itself should
be included in the search. Defaults to `true`.
Returns the closest available context node to the one specified . The DOM traversal goes at most as far as the root node ( document shadow root document fragment ) or as far as the DOM tree allows . The traversal follows the assigned shadow slots . Root nodes ( document or shadow root ) and AMP elements are auto - created during the traversal . @param { Node } node The node from which to perform the search . @param { boolean = } includeSelf Whether the specified node itself should be included in the search . Defaults to ` true ` .
static closest(node, includeSelf = true) {
    let n = node;
    while (n) {
      if (n != node || includeSelf) {
        if (n[NODE_PROP]) {
          return  (n[NODE_PROP]);
        }
        const {nodeType} = n;
        if (
          nodeType == DOCUMENT_NODE ||
          nodeType == FRAGMENT_NODE ||
          (isElement(n) && n.tagName.startsWith(AMP_PREFIX))
        ) {
          return ContextNode.get(n);
        }
      }
      const assignedSlot =
         (n[ASSIGNED_SLOT_PROP]) ||
         (n).assignedSlot;
      if (assignedSlot) {
        n = assignedSlot;
      } else {
        n =  (n.parentNode);
      }
    }
    return null;
  }
static closest ( node , includeSelf = true ) { let n = node ; while ( n ) { if ( n != node || includeSelf ) { if ( n [ NODE_PROP ] ) { return ( n [ NODE_PROP ] ) ; } const { nodeType } = n ; if ( nodeType == DOCUMENT_NODE || nodeType == FRAGMENT_NODE || ( isElement ( n ) && n . tagName . startsWith ( AMP_PREFIX ) ) ) { return ContextNode . get ( n ) ; } } const assignedSlot = ( n [ ASSIGNED_SLOT_PROP ] ) || ( n ) . assignedSlot ; if ( assignedSlot ) { n = assignedSlot ; } else { n = ( n . parentNode ) ; } } return null ; }
Returns the closest available context node to the one specified.
Returns the closest available context node to the one specified .
/** @type {?Node} */ // Check if a node is a candidate to be returned. // Already a discovered node. /** @type {ContextNode<?>} */ // A context node is always created for a root. Due to this, a // non-root element is always at least attached to a root. This // allows for quick discovery and reattachment when new information // becomes available. // An AMP node will always have a context node backing it at some // point. // Navigate up the DOM tree. Notice that we do not automatically go over // a root node boundary. /** @type {Node|Element|undefined|null} */ /** @type {?Node|undefined} */ /** @type {Element} */ /** @type {?Node} */ // Only disconnected nodes will return `null` here.