-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure non-matching elements are scoped for
:not(...)
selector (…
…#13999) If the contents of a `:not` selector don't match, then it's actually a match for `:not` because it's inverted. Therefore, we need to scope such elements. We're also making sure that contents of `:not` that never match actually count as a used (because the result is negated), and as such the contents of `:not` that always match are actually marked as unused. Fixes #13974
- Loading branch information
1 parent
57e27ae
commit 7dbe812
Showing
14 changed files
with
172 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: ensure non-matching elements are scoped for `:not(...)` selector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/svelte/tests/css/samples/not-selector-global/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
warnings: [ | ||
{ | ||
code: 'css_unused_selector', | ||
message: 'Unused CSS selector ":global(.x) :not(p)"', | ||
start: { | ||
line: 14, | ||
column: 1, | ||
character: 197 | ||
}, | ||
end: { | ||
line: 14, | ||
column: 20, | ||
character: 216 | ||
} | ||
} | ||
] | ||
}); |
19 changes: 19 additions & 0 deletions
19
packages/svelte/tests/css/samples/not-selector-global/expected.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
.svelte-xyz:not(.foo) { | ||
color: green; | ||
} | ||
.svelte-xyz:not(.foo:where(.svelte-xyz)):not(.unused) { | ||
color: green; | ||
} | ||
.x:not(.foo.svelte-xyz) { | ||
color: green; | ||
} | ||
/* (unused) :global(.x) :not(p) { | ||
color: red; | ||
}*/ | ||
.x:not(p.svelte-xyz) { | ||
color: red; /* TODO would be nice to prune this one day */ | ||
} | ||
.x .svelte-xyz:not(.unused:where(.svelte-xyz)) { | ||
color: green; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/svelte/tests/css/samples/not-selector-global/expected.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p class="foo svelte-xyz">foo</p> <p class="bar svelte-xyz">bar</p> |
23 changes: 23 additions & 0 deletions
23
packages/svelte/tests/css/samples/not-selector-global/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<p class="foo">foo</p> | ||
<p class="bar">bar</p> | ||
|
||
<style> | ||
:not(:global(.foo)) { | ||
color: green; | ||
} | ||
:not(.foo):not(:global(.unused)) { | ||
color: green; | ||
} | ||
:global(.x):not(.foo) { | ||
color: green; | ||
} | ||
:global(.x) :not(p) { | ||
color: red; | ||
} | ||
:global(.x):not(p) { | ||
color: red; /* TODO would be nice to prune this one day */ | ||
} | ||
:global(.x) :not(.unused) { | ||
color: green; | ||
} | ||
</style> |
5 changes: 5 additions & 0 deletions
5
packages/svelte/tests/css/samples/not-selector-hash-on-right-elements/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
warnings: [] | ||
}); |
4 changes: 4 additions & 0 deletions
4
packages/svelte/tests/css/samples/not-selector-hash-on-right-elements/expected.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
.svelte-xyz:not(.bar:where(.svelte-xyz)) { | ||
color: green; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/svelte/tests/css/samples/not-selector-hash-on-right-elements/expected.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p class="foo svelte-xyz">foo</p> <p class="bar">bar</p> |
8 changes: 8 additions & 0 deletions
8
packages/svelte/tests/css/samples/not-selector-hash-on-right-elements/input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<p class="foo">foo</p> | ||
<p class="bar">bar</p> | ||
|
||
<style> | ||
:not(.bar) { | ||
color: green; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.