diff --git a/index.js b/index.js index 1b42b51..f888641 100644 --- a/index.js +++ b/index.js @@ -7,9 +7,16 @@ const selectorProcessor = selectorParser(selectors => { if ( selector.type === 'pseudo' && selector.toString() === ':hover' && - selector.parent.value !== ':not' && selector.parent.toString() !== ':hover' ) { + let parent = selector.parent + while (parent !== undefined) { + if (parent.value === ':has' || parent.value === ':not') { + return + } + + parent = parent.parent + } hoverSelectors.push(selector.parent.toString()) } }) diff --git a/index.test.js b/index.test.js index c9e74c7..349f0e4 100644 --- a/index.test.js +++ b/index.test.js @@ -75,6 +75,20 @@ describe('basic usage', () => { '.list__item:not(:hover, .is-editing) .show-on-hover { visibility: hidden }' ) }) + + it('ignores nested :hover pseudo-class selectors within :not pseudo-class selector lists', () => { + run( + '.list__item:not(.some-selector:hover) .show-on-hover { visibility: hidden }', + '.list__item:not(.some-selector:hover) .show-on-hover { visibility: hidden }' + ) + }) + + it('ignores :hover pseudo-class selectors within :has pseudo-class selector lists', () => { + run( + '.list__item:has(.some-selector:hover) .show-on-hover { visibility: hidden }', + '.list__item:has(.some-selector:hover) .show-on-hover { visibility: hidden }' + ) + }) }) describe('when `fallback: true`', () => {