Skip to content

Commit 8f6853d

Browse files
authored
postcss-is-pseudo : fix has pseudo (#1139)
1 parent 71acf0f commit 8f6853d

11 files changed

+108
-62
lines changed

plugins/postcss-is-pseudo-class/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes to PostCSS Is Pseudo Class
22

3+
### Unreleased (patch)
4+
5+
- Prevent incorrect transforms when `:is()` is wrapped in `:has()`.
6+
37
### 4.0.2
48

59
_September 18, 2023_

plugins/postcss-is-pseudo-class/dist/index.cjs

+1-1
Large diffs are not rendered by default.

plugins/postcss-is-pseudo-class/dist/index.mjs

+1-1
Large diffs are not rendered by default.

plugins/postcss-is-pseudo-class/src/split-selectors/split-selectors.ts

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ export default function splitSelectors(selectors: Array<string>, pluginOptions:
4141
return;
4242
}
4343

44+
if (pseudo.parent?.parent?.type === 'pseudo' && pseudo.parent?.parent?.value?.toLowerCase() === ':has') {
45+
pseudo.value = ':-csstools-matches';
46+
47+
return;
48+
}
49+
4450
let parent = pseudo.parent;
4551
while (parent) {
4652
if (parent.value && parent.value.toLowerCase() === ':is' && parent.type === 'pseudo') {

plugins/postcss-is-pseudo-class/test/basic.css

+12
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,15 @@ header:is(.a .b) {
161161
>:is(.a .b) {
162162
color: green;
163163
}
164+
165+
:has(:is(.foo .bar)) {
166+
color: green;
167+
}
168+
169+
:has(:is(.foo .bar), .fooz .bar) {
170+
color: green;
171+
}
172+
173+
:has(:is(.foo .bar) .fooz) {
174+
color: green;
175+
}

plugins/postcss-is-pseudo-class/test/basic.does-not-exist.expect.css

+13-9
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,7 @@ ol:hover > li.foo, ol:hover > li.bar, ol:focus > li.foo, ol:focus > li.bar, ul:h
226226
order: 35;
227227
}
228228

229-
:has(h1) {
230-
order: 36;
231-
}
232-
233-
:has(h2) {
234-
order: 36;
235-
}
236-
237-
:has(h3) {
229+
:has(:is(h1, h2, h3)) {
238230
order: 36;
239231
}
240232

@@ -269,3 +261,15 @@ input:hover, input:focus, button:hover, button:focus {
269261
>:is(.a .b) {
270262
color: green;
271263
}
264+
265+
:has(:is(.foo .bar)) {
266+
color: green;
267+
}
268+
269+
:has( .fooz .bar,:is(.foo .bar)) {
270+
color: green;
271+
}
272+
273+
:has(:is(.foo .bar) .fooz) {
274+
color: green;
275+
}

plugins/postcss-is-pseudo-class/test/basic.expect.css

+13-9
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,7 @@ ol:hover > li.foo, ol:hover > li.bar, ol:focus > li.foo, ol:focus > li.bar, ul:h
226226
order: 35;
227227
}
228228

229-
:has(h1) {
230-
order: 36;
231-
}
232-
233-
:has(h2) {
234-
order: 36;
235-
}
236-
237-
:has(h3) {
229+
:has(:is(h1, h2, h3)) {
238230
order: 36;
239231
}
240232

@@ -269,3 +261,15 @@ input:hover, input:focus, button:hover, button:focus {
269261
>:is(.a .b) {
270262
color: green;
271263
}
264+
265+
:has(:is(.foo .bar)) {
266+
color: green;
267+
}
268+
269+
:has( .fooz .bar,:is(.foo .bar)) {
270+
color: green;
271+
}
272+
273+
:has(:is(.foo .bar) .fooz) {
274+
color: green;
275+
}

plugins/postcss-is-pseudo-class/test/basic.oncomplex.no-warning.expect.css

+13-9
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,7 @@ ol:hover > li.foo, ol:hover > li.bar, ol:focus > li.foo, ol:focus > li.bar, ul:h
226226
order: 35;
227227
}
228228

229-
:has(h1) {
230-
order: 36;
231-
}
232-
233-
:has(h2) {
234-
order: 36;
235-
}
236-
237-
:has(h3) {
229+
:has(:is(h1, h2, h3)) {
238230
order: 36;
239231
}
240232

@@ -269,3 +261,15 @@ input:hover, input:focus, button:hover, button:focus {
269261
>:is(.a .b) {
270262
color: green;
271263
}
264+
265+
:has(:is(.foo .bar)) {
266+
color: green;
267+
}
268+
269+
:has( .fooz .bar,:is(.foo .bar)) {
270+
color: green;
271+
}
272+
273+
:has(:is(.foo .bar) .fooz) {
274+
color: green;
275+
}

plugins/postcss-is-pseudo-class/test/basic.oncomplex.warning.expect.css

+13-9
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,7 @@ ol:hover > li.foo, ol:hover > li.bar, ol:focus > li.foo, ol:focus > li.bar, ul:h
226226
order: 35;
227227
}
228228

229-
:has(h1) {
230-
order: 36;
231-
}
232-
233-
:has(h2) {
234-
order: 36;
235-
}
236-
237-
:has(h3) {
229+
:has(:is(h1, h2, h3)) {
238230
order: 36;
239231
}
240232

@@ -269,3 +261,15 @@ input:hover, input:focus, button:hover, button:focus {
269261
>:is(.a .b) {
270262
color: green;
271263
}
264+
265+
:has(:is(.foo .bar)) {
266+
color: green;
267+
}
268+
269+
:has( .fooz .bar,:is(.foo .bar)) {
270+
color: green;
271+
}
272+
273+
:has(:is(.foo .bar) .fooz) {
274+
color: green;
275+
}

plugins/postcss-is-pseudo-class/test/basic.preserve.expect.css

+16-12
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,6 @@ ol:hover > li.foo, ol:hover > li.bar, ol:focus > li.foo, ol:focus > li.bar, ul:h
350350
order: 35;
351351
}
352352

353-
:has(h1) {
354-
order: 36;
355-
}
356-
357-
:has(h2) {
358-
order: 36;
359-
}
360-
361-
:has(h3) {
362-
order: 36;
363-
}
364-
365353
:has(:is(h1, h2, h3)) {
366354
order: 36;
367355
}
@@ -413,3 +401,19 @@ header:is(.a .b) {
413401
>:is(.a .b) {
414402
color: green;
415403
}
404+
405+
:has(:is(.foo .bar)) {
406+
color: green;
407+
}
408+
409+
:has( .fooz .bar,:is(.foo .bar)) {
410+
color: green;
411+
}
412+
413+
:has(:is(.foo .bar), .fooz .bar) {
414+
color: green;
415+
}
416+
417+
:has(:is(.foo .bar) .fooz) {
418+
color: green;
419+
}

plugins/postcss-is-pseudo-class/test/basic.with-cloned-declarations.expect.css

+16-12
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,6 @@ ol:hover > li.foo, ol:hover > li.bar, ol:focus > li.foo, ol:focus > li.bar, ul:h
350350
order: 35;
351351
}
352352

353-
:has(h1) {
354-
order: 36;
355-
}
356-
357-
:has(h2) {
358-
order: 36;
359-
}
360-
361-
:has(h3) {
362-
order: 36;
363-
}
364-
365353
:has(:is(h1, h2, h3)) {
366354
order: 36;
367355
}
@@ -415,3 +403,19 @@ header:is(.a .b) {
415403
>:is(.a .b) {
416404
color: green;
417405
}
406+
407+
:has(:is(.foo .bar)) {
408+
color: green;
409+
}
410+
411+
:has( .fooz .bar,:is(.foo .bar)) {
412+
color: green;
413+
}
414+
415+
:has(:is(.foo .bar), .fooz .bar) {
416+
color: green;
417+
}
418+
419+
:has(:is(.foo .bar) .fooz) {
420+
color: green;
421+
}

0 commit comments

Comments
 (0)