Skip to content

Commit 69d4b66

Browse files
authored
Fix child combinator :where selectors (#268)
1 parent 289b2ba commit 69d4b66

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/index.js

+14-17
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,30 @@ const computed = {
1010

1111
function inWhere(selector, { className, prefix }) {
1212
let prefixedNot = prefix(`.not-${className}`).slice(1)
13+
let selectorPrefix = selector.startsWith('>') ? `.${className} ` : ''
1314

1415
if (selector.endsWith('::before')) {
15-
if (selector.startsWith('>')) {
16-
return `> :where(${selector.slice(2, -8)}):not(:where([class~="${prefixedNot}"] *))::before`
17-
}
18-
return `:where(${selector.slice(0, -8)}):not(:where([class~="${prefixedNot}"] *))::before`
16+
return `:where(${selectorPrefix}${selector.slice(
17+
0,
18+
-8
19+
)}):not(:where([class~="${prefixedNot}"] *))::before`
1920
}
2021

2122
if (selector.endsWith('::after')) {
22-
if (selector.startsWith('>')) {
23-
return `> :where(${selector.slice(2, -7)}):not(:where([class~="${prefixedNot}"] *))::after`
24-
}
25-
return `:where(${selector.slice(0, -7)}):not(:where([class~="${prefixedNot}"] *))::after`
23+
return `:where(${selectorPrefix}${selector.slice(
24+
0,
25+
-7
26+
)}):not(:where([class~="${prefixedNot}"] *))::after`
2627
}
2728

2829
if (selector.endsWith('::marker')) {
29-
if (selector.startsWith('>')) {
30-
return `> :where(${selector.slice(2, -8)}):not(:where([class~="${prefixedNot}"] *))::marker`
31-
}
32-
return `:where(${selector.slice(0, -8)}):not(:where([class~="${prefixedNot}"] *))::marker`
33-
}
34-
35-
if (selector.startsWith('>')) {
36-
return `> :where(${selector.slice(2)}):not(:where([class~="${prefixedNot}"] *))`
30+
return `:where(${selectorPrefix}${selector.slice(
31+
0,
32+
-8
33+
)}):not(:where([class~="${prefixedNot}"] *))::marker`
3734
}
3835

39-
return `:where(${selector}):not(:where([class~="${prefixedNot}"] *))`
36+
return `:where(${selectorPrefix}${selector}):not(:where([class~="${prefixedNot}"] *))`
4037
}
4138

4239
function isObject(value) {

src/index.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ test('specificity is reduced with :where', async () => {
158158
font-weight: 400;
159159
color: var(--tw-prose-counters);
160160
}
161-
.prose > :where(ul > li p):not(:where([class~='not-prose'] *)) {
161+
.prose :where(.prose > ul > li p):not(:where([class~='not-prose'] *)) {
162162
margin-top: 16px;
163163
margin-bottom: 16px;
164164
}

0 commit comments

Comments
 (0)