Skip to content

fix: infinite loop when :hover is contained in :has or nested :not selector #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
})
Expand Down
14 changes: 14 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`', () => {
Expand Down