fix: applying :global for +,~ sibling combinator when slots are present. fixes #9274 by kelvinsjk · Pull Request #9282 · sveltejs/svelte (original) (raw)
fixes #9274
For the following,
<div>
<slot/>
<span>xxx</span>
</div>
the style :global(p) + span could be applied because the slot could contain the required p element.
The current code did not apply the style because siblings.size===0 during compilation. To fix it, the existing find_previous_sibling and get_possible_element_siblings functions were modified to also return whether a sibling slot has been found. We only flag a css selector as inapplicable if, in addition to the existing checks on sibling size and parent, if there are no previous sibling that are slots found.
Svelte compiler rewrite
Please note that the Svelte codebase is currently being rewritten. Thus, it's best to hold off on new features or refactorings for the time being.
Before submitting the PR, please make sure you do the following
- It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- Prefix your PR title with
feat:,fix:,chore:, ordocs:. - This message body should clearly illustrate what problems it solves.
- Ideally, include a test that fails without this PR but passes with it.
Tests and linting
- Run the tests with
pnpm testand lint the project withpnpm lint