<commit_before>const win        = require('./window');
const browser    = require('./browser');
const isType     = require('./isType');
const domObjects = require('./domObjects');

const domUtils = {
  nodeContains: function (parent, child) {
    while (child) {
      if (child === parent) {
        return true;
      }

      child = child.parentNode;
    }

    return false;
  },

  closest: function (child, selector) {
    let parent = domUtils.parentElement(child);

    while (isType.isElement(parent)) {
      if (domUtils.matchesSelector(parent, selector)) { return parent; }

      parent = domUtils.parentElement(parent);
    }

    return null;
  },

  parentElement: function (node) {
    let parent = node.parentNode;

    if (isType.isDocFrag(parent)) {
      // skip past #shado-root fragments
      while ((parent = parent.host) && isType.isDocFrag(parent)) {
        continue;
      }

      return parent;<commit_msg>utils/domUtils: fix closest to match native impl<commit_after>const win        = require('./window');
const browser    = require('./browser');
const isType     = require('./isType');
const domObjects = require('./domObjects');

const domUtils = {
  nodeContains: function (parent, child) {
    while (child) {
      if (child === parent) {
        return true;
      }

      child = child.parentNode;
    }

    return false;
  },

  closest: function (element, selector) {
    while (isType.isElement(element)) {
      if (domUtils.matchesSelector(element, selector)) { return element; }

      element = domUtils.parentElement(element);
    }

    return null;
  },

  parentElement: function (node) {
    let parent = node.parentNode;

    if (isType.isDocFrag(parent)) {
      // skip past #shado-root fragments
      while ((parent = parent.host) && isType.isDocFrag(parent)) {
        continue;
      }

      return parent;
{'fraction_non_alphanumeric': 0.1332263242375602, 'fraction_numerical': 0.0, 'mean_word_length': 2.6811023622047245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7019937', 'n_tokens_mistral': 547, 'n_tokens_neox': 534, 'n_words': 134}