-
-
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 explicit nesting selector is always applied (#14193)
Previously, we were applying an explicit nesting selector to the start of a relative selector chain only when starting the traversal. Prepending the selector is important because it ensures we traverse upwards to the parent rule when the current selectors all matched and there's still more to do. But we forgot to do the prepend for parent rules, which meant that if we were nested two levels deep, we would stop too early. This fix ensures we prepend in that case, too. Fixes #14178
- Loading branch information
1 parent
d7caf08
commit 1eed645
Showing
10 changed files
with
179 additions
and
54 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 explicit nesting selector is always applied |
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
5 changes: 0 additions & 5 deletions
5
packages/svelte/tests/css/samples/nested-in-pseudo/_config.js
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
packages/svelte/tests/css/samples/nested-in-pseudo/expected.css
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/svelte/tests/css/samples/nested-in-pseudo/expected.html
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
packages/svelte/tests/css/samples/nested-in-pseudo/input.svelte
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
packages/svelte/tests/css/samples/nesting-selectors/_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,48 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({ | ||
warnings: [ | ||
{ | ||
code: 'css_unused_selector', | ||
message: 'Unused CSS selector ".unused:has(&)"', | ||
start: { | ||
line: 10, | ||
column: 2, | ||
character: 105 | ||
}, | ||
end: { | ||
line: 10, | ||
column: 16, | ||
character: 119 | ||
} | ||
}, | ||
{ | ||
code: 'css_unused_selector', | ||
message: 'Unused CSS selector "&.unused"', | ||
start: { | ||
line: 23, | ||
column: 3, | ||
character: 223 | ||
}, | ||
end: { | ||
line: 23, | ||
column: 11, | ||
character: 231 | ||
} | ||
}, | ||
{ | ||
code: 'css_unused_selector', | ||
message: 'Unused CSS selector "&.unused"', | ||
start: { | ||
line: 37, | ||
column: 3, | ||
character: 344 | ||
}, | ||
end: { | ||
line: 37, | ||
column: 11, | ||
character: 352 | ||
} | ||
} | ||
] | ||
}); |
37 changes: 37 additions & 0 deletions
37
packages/svelte/tests/css/samples/nesting-selectors/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,37 @@ | ||
|
||
nav.svelte-xyz { | ||
header:where(.svelte-xyz):has(&){ | ||
color: green; | ||
} | ||
/* (unused) .unused:has(&){ | ||
color: red; | ||
}*/ | ||
} | ||
|
||
header.svelte-xyz { | ||
> nav:where(.svelte-xyz) { | ||
color: green; | ||
|
||
&.active { | ||
color: green; | ||
} | ||
|
||
/* (unused) &.unused { | ||
color: red; | ||
}*/ | ||
} | ||
} | ||
|
||
header.svelte-xyz { | ||
& > nav:where(.svelte-xyz) { | ||
color: green; | ||
|
||
&.active { | ||
color: green; | ||
} | ||
|
||
/* (unused) &.unused { | ||
color: red; | ||
}*/ | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
packages/svelte/tests/css/samples/nesting-selectors/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 @@ | ||
<header class="svelte-xyz"><nav class="active svelte-xyz"></nav></header> |
42 changes: 42 additions & 0 deletions
42
packages/svelte/tests/css/samples/nesting-selectors/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,42 @@ | ||
<header> | ||
<nav class="active"></nav> | ||
</header> | ||
|
||
<style> | ||
nav { | ||
header:has(&){ | ||
color: green; | ||
} | ||
.unused:has(&){ | ||
color: red; | ||
} | ||
} | ||
header { | ||
> nav { | ||
color: green; | ||
&.active { | ||
color: green; | ||
} | ||
&.unused { | ||
color: red; | ||
} | ||
} | ||
} | ||
header { | ||
& > nav { | ||
color: green; | ||
&.active { | ||
color: green; | ||
} | ||
&.unused { | ||
color: red; | ||
} | ||
} | ||
} | ||
</style> |