includesAttrSelector = (
  selector,
  name,
  value = null,
  traversed = false,
) => {
  const selectors =
    typeof selector === 'string'
      ? csswhat.parse(selector)
      : csswhat.parse(csstree.generate(selector.data));

  for (const subselector of selectors) {
    const hasAttrSelector = subselector.some((segment, index) => {
      if (traversed) {
        if (index === subselector.length - 1) {
          return false;
        }

        const isNextTraversal = csswhat.isTraversal(subselector[index + 1]);

        if (!isNextTraversal) {
          return false;
        }
      }

      if (segment.type !== 'attribute' || segment.name !== name) {
        return false;
      }

      return value == null ? true : segment.value === value;
    });

    if (hasAttrSelector) {
      return true;
    }
  }

  return false;
}
Determines if the CSS selector includes or traverses the given attribute.

Classes and IDs are generated as attribute selectors, so you can check for if
a `.class` or `#id` is included by passing `name=class` or `name=id`
respectively.

@param {csstree.ListItem<csstree.CssNode> | string} selector
@param {string} name
@param {?string} value
@param {boolean} traversed
@returns {boolean}