-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
breaking: scope :not(...) selectors #13568
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
Conversation
The main part of #13395 This implements scoping for selectors inside `:has(...)`. The approach is to first descend into the contents of a `:has(...)` selector, then in case of a match, try to match the rest of the selector ignoring the `:has(...)` part. In other words, `.x:has(y)` is essentially treated as `x y` with `y` being matched first, then walking up the selector chain taking into account combinators. This is a breaking change because people could've used `:has(.unknown)` with `.unknown` not appearing in the HTML, and so they need to do `:has(:global(.unknown))` instead
The other part of #13395 This implements scoping for selectors inside `:not(...)`. The approach is almot the same as for `:is/where(...)`. This is a breaking change because people could've used `:not(.unknown)` with `.unknown` not appearing in the HTML, and so they need to do `:not(:global(.unknown))` instead. While implementing it I also discovered a few bugs, which are fixed in this PR: - `foo :is(bar baz)` wasn't properly handled. This selector can mean `foo bar baz` but it can also mean `bar foo baz` (super weird, but it is what it is). Since our current algorithm isn't suited for handling this, we just assume it matches and scope it. Worst case is we missed a prune - `bar` in `:global(foo):is(bar)` was always marked as unused, even if it matched
🦋 Changeset detectedLatest commit: 37f10e6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@dummdidumm Mind rebasing the PR before I review please? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Nice work.
The other part of, and therefore closes #13395
This implements scoping for selectors inside
:not(...)
. The approach is almot the same as for:is/where(...)
.This is a breaking change because people could've used
:not(.unknown)
with.unknown
not appearing in the HTML, and so they need to do:not(:global(.unknown))
instead.While implementing it I also discovered a few bugs, which are fixed in this PR:
foo :is(bar baz)
wasn't properly handled. This selector can meanfoo bar baz
but it can also meanbar foo baz
(super weird, but it is what it is). Since our current algorithm isn't suited for handling this, we just assume it matches and scope it. Worst case is we missed a prunebar
in:global(foo):is(bar)
was always marked as unused, even if it matchedBefore submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint