fix: correctly match :has()'s selector during css pruning
#15277
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #14072, alternative of #15207
:has()was matching only against descendants or siblings, but not sibling's descendants.In this variant, I made
apply_selectorand related functions bidirectional. So the same logic can be applied to all selectors.Changing the direction for selectors passed into
:has()brokep:has(+ y)for the testhas-with-render-tagand to fix it I added diving into the@render()tags during gathering siblings, which fixed therender-tag-looptest.I also tried to cache the function retrieving neighbor elements and got the following cache hits rates on the test cases:
descendant_forward: 94,23%
descendant_backward: 55,91%
children_forward: 84,00%
children_backward: 33,51%
sibling_forward: 69,42%
sibling_backward: 59,94%
next_forward: 41,40%
next_backward: 2,44%
Though, I'm not sure how to measure performance change.
Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lint