<commit_before>
import classNames from 'classnames';

export function parseTag (tag) {
  const cell = { attrs: {}, classes: [] };
  const parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g;
  let match;

  // eslint-disable-next-line no-cond-assign
  while ((match = parser.exec(tag))) {
    if (match[1] === '' && match[2]) {
      cell.tag = match[2];
    } else if (match[1] === '#') {
      cell.attrs.id = match[2];
    } else if (match[1] === '.') {
      cell.classes.push(match[2]);
    } else if (match[3][0] === '[') {
      const pair = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/.exec(match[3]);
      cell.attrs[pair[1]] = pair[3] || '';
    }
  }

  return cell;
}

function isAttributesObject (attrs) {
  return attrs && typeof attrs === 'object' && !Array.isArray(attrs) && !attrs.children;
}

export function extendHyperscript (createElement) {
  return function hyperscript (tag, ...args) {
    // Sub-components
    if (tag instanceof Function) return tag(...args);

    // Hyperscript extension (div.class-name#someid[attr=value])
    const parsed = parseTag(tag);
    const attrs = args[0];

    if (isAttributesObject(attrs)) {
      Object.assign(parsed.attrs, attrs);
      parsed.attrs.className = classNames(attrs.className, parsed.classes);
      parsed.children = args.slice(1);
    } else {
      parsed.attrs.className = classNames(parsed.classes);
      parsed.children = args;
    }<commit_msg>Add classnames processing for sub components as well<commit_after>
import classNames from 'classnames';

export function parseTag (tag) {
  const cell = { attrs: {}, classes: [] };
  const parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g;
  let match;

  // eslint-disable-next-line no-cond-assign
  while ((match = parser.exec(tag))) {
    if (match[1] === '' && match[2]) {
      cell.tag = match[2];
    } else if (match[1] === '#') {
      cell.attrs.id = match[2];
    } else if (match[1] === '.') {
      cell.classes.push(match[2]);
    } else if (match[3][0] === '[') {
      const pair = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/.exec(match[3]);
      cell.attrs[pair[1]] = pair[3] || '';
    }
  }

  return cell;
}

function isAttributesObject (attrs) {
  return attrs && typeof attrs === 'object' && !Array.isArray(attrs) && !attrs.children;
}

export function extendHyperscript (createElement) {
  return function hyperscript (tag, attrs, ...children) {
    // Sub-components
    if (tag instanceof Function) {
      if (isAttributesObject(attrs)) attrs.className = classNames(attrs.className);
      return tag(attrs, ...children);
    }

    // Hyperscript extension (div.class-name#someid[attr=value])
    const parsed = parseTag(tag);

    if (isAttributesObject(attrs)) {
      Object.assign(parsed.attrs, attrs);
      parsed.attrs.className = classNames(attrs.className, parsed.classes);
      parsed.children = children;
    } else {
      parsed.attrs.className = classNames(parsed.classes);
      parsed.children = [attrs].concat(children);
    }
{'fraction_non_alphanumeric': 0.20559487698011458, 'fraction_numerical': 0.009437141894169195, 'mean_word_length': 3.1051175656984786, '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': '1956252', 'n_tokens_mistral': 988, 'n_tokens_neox': 987, 'n_words': 202}