Skip to content
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

scope css sibling combinator #5427

Merged
merged 7 commits into from Sep 24, 2020
Merged

Conversation

tanhauhau
Copy link
Member

@tanhauhau tanhauhau commented Sep 19, 2020

Implement css scoping for ~ and + css sibling combinator

Fixes #3104

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
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with npm test and lint the project with npm run lint

@Conduitry
Copy link
Member

What are the new NodeExist.Definitely and NodeExist.Probably values for? When are we saying something 'probably' matches, and what do we do in that situation?

@tanhauhau
Copy link
Member Author

ok the gist of what I'm trying to do here is that, for example:

<div id="a" />
<div id="b" />

{#each foo}
   <div id="c" />
{/each}

<div id="d" />

#d tries to find it's siblings iteratively through element.prev.
in this case, it gets {#each} block and it has #c, which probably exist (NodeExist.Probably), because it's in an each block.
so i continue search it's sibling iteratively, and the next element is #b. #b definitely exists. (NodeExist.Definitely)
so i stop the search.

so both #b + #d and #c + #d will be marked as match, but not #a + #d

however, for another example:

<div id="a" />

{#each foo}
   <div id="b" />
{:else}
   <div id="c" />
{/each}

<div id="d" />

#d tries to find it's siblings.
in this case, {#each} block contains either #b or #c. but they definitely exists, one or the other.
so i stop the search.

so both #b + #d and #c + #d will be marked as match, but not #a + #d

@tanhauhau
Copy link
Member Author

tanhauhau commented Sep 22, 2020

i've tried to come up with test cases with different nested logic blocks:

{#each foo}
   {#if bar}
       <div id="a"/>
   {/if}
{:else}
   <div id="b" />
{/if}

here #a and #b is probably exist.

hopefully im able to cover all of the edge cases 😅

@Conduitry Conduitry merged commit 967b881 into sveltejs:master Sep 24, 2020
@tanhauhau tanhauhau deleted the tanhauhau/gh-3104 branch September 25, 2020 02:31
@non25
Copy link

non25 commented Nov 2, 2020

@tanhauhau Hi, this PR broke selectors like this one:

:global(*) + .button.margin {
  margin-top: 8px;
}

They are getting stripped despite global. I used them in Button, Input and Checkbox components.
Can you fix it?

Repro:

https://svelte.dev/repl/5ec4d420b4b44ea4b441da24010d8acd?version=3.26.0
https://svelte.dev/repl/5ec4d420b4b44ea4b441da24010d8acd?version=3.29.4

taylorzane pushed a commit to taylorzane/svelte that referenced this pull request Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lobotomized owl CSS selector broken
3 participants