Skip to content

Commit c74cb2b

Browse files
authored
postcss-nesting: nested conditionals (#1368)
1 parent 4990e96 commit c74cb2b

9 files changed

+108
-46
lines changed

plugins/postcss-nesting/CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# Changes to PostCSS Nesting
22

3+
### Unreleased (patch)
4+
5+
- Edition `2024-02`:
6+
- Do not rewrite selectors for declarations in conditional rules to a form with `:is()`
7+
8+
This will work:
9+
```css
10+
::before, ::after {
11+
color: blue;
12+
13+
@media screen { color: cyan; }
14+
}
15+
```
16+
17+
This still **wont** work:
18+
```css
19+
::before, ::after {
20+
color: blue;
21+
22+
&:hover { color: cyan; }
23+
}
24+
```
25+
326
### 12.1.1
427

528
_March 31, 2024_

plugins/postcss-nesting/dist/index.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

plugins/postcss-nesting/dist/index.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

plugins/postcss-nesting/src/editions/2024-02/lib/atrule-within-rule.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { AtRule, Result, Rule } from 'postcss';
22
import type { walkFunc } from './walk-func.js';
33
import cleanupParent from '../../shared/lib/cleanup-parent.js';
4-
import mergeSelectors from './merge-selectors.js';
54
import shiftNodesBeforeParent from '../../shared/lib/shift-nodes-before-parent.js';
65
import validAtrules from '../../shared/lib/valid-atrules.js';
76

@@ -13,13 +12,6 @@ export default function atruleWithinRule(node: AtRule, parent: Rule, result: Res
1312
if (node.nodes) {
1413
const rule = parent.clone().removeAll().append(node.nodes);
1514

16-
const selectors = mergeSelectors(node, '&', parent.selector, result);
17-
if (!selectors) {
18-
return;
19-
}
20-
21-
rule.selector = selectors;
22-
2315
// append the new rule to the node
2416
node.append(rule);
2517

plugins/postcss-nesting/test/media.edition-2024-02.expect.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ a {
1111
}
1212
}
1313
@media (max-width: 200px) {
14-
:is(a b) {
14+
a b {
1515
order: 4;
1616
}
1717
}
@@ -39,7 +39,7 @@ a {
3939
}
4040
}
4141
@media (max-width: 200px) {
42-
:is(a b) {
42+
a b {
4343
order: 4;
4444
}
4545
}
@@ -57,14 +57,14 @@ a {
5757

5858
@media screen {
5959

60-
:is(a,.a) {
60+
a, .a {
6161
order: 7;
6262
}
6363
}
6464

6565
@media screen {
6666

67-
:is(a,a::after) {
67+
a, a::after {
6868
order: 8;
6969
}
7070
}

plugins/postcss-nesting/test/spec-examples.css

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,6 @@ article {
377377
color: blue;
378378
}
379379

380-
/*
381-
NOTE : We are more forgiving than the spec
382-
This declaration is preserved
383-
*/
384380
color: red;
385381
}
386382

@@ -391,10 +387,6 @@ article {
391387
color: blue;
392388
}
393389

394-
/*
395-
NOTE : We are more forgiving than the spec
396-
This declaration is preserved
397-
*/
398390
color: red;
399391

400392
&.foo {
@@ -403,3 +395,19 @@ article {
403395

404396
/* valid! */
405397
}
398+
399+
::after, .foo {
400+
color: green;
401+
402+
& {
403+
color: blue;
404+
}
405+
406+
color: red;
407+
408+
@media screen {
409+
color: purple;
410+
}
411+
412+
color: orange;
413+
}

plugins/postcss-nesting/test/spec-examples.edition-2024-02.expect.css

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,6 @@ article {
353353
article {
354354
color: blue;
355355

356-
/*
357-
NOTE : We are more forgiving than the spec
358-
This declaration is preserved
359-
*/
360356
color: red;
361357
}
362358

@@ -367,10 +363,6 @@ article {
367363
article {
368364
color: blue;
369365

370-
/*
371-
NOTE : We are more forgiving than the spec
372-
This declaration is preserved
373-
*/
374366
color: red;
375367
}
376368

@@ -379,3 +371,28 @@ article.foo {
379371
}
380372

381373
/* valid! */
374+
375+
::after, .foo {
376+
color: green;
377+
}
378+
379+
:is(::after,.foo) {
380+
color: blue;
381+
}
382+
383+
::after, .foo {
384+
385+
color: red;
386+
}
387+
388+
@media screen {
389+
390+
::after, .foo {
391+
color: purple;
392+
}
393+
}
394+
395+
::after, .foo {
396+
397+
color: orange;
398+
}

plugins/postcss-nesting/test/spec-examples.expect.css

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,6 @@ __bar.foo {
358358
article {
359359
color: green;
360360

361-
/*
362-
NOTE : We are more forgiving than the spec
363-
This declaration is preserved
364-
*/
365361
color: red;
366362
}
367363
article {
@@ -371,10 +367,6 @@ article {
371367
article {
372368
color: green;
373369

374-
/*
375-
NOTE : We are more forgiving than the spec
376-
This declaration is preserved
377-
*/
378370
color: red;
379371
}
380372

@@ -387,3 +379,22 @@ article.foo {
387379
}
388380

389381
/* valid! */
382+
383+
::after, .foo {
384+
color: green;
385+
386+
color: red;
387+
388+
color: orange;
389+
}
390+
391+
:is(::after,.foo) {
392+
color: blue;
393+
}
394+
395+
@media screen {
396+
397+
::after, .foo {
398+
color: purple;
399+
}
400+
}

plugins/postcss-nesting/test/spec-examples.no-is-pseudo-selector.expect.css

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,6 @@ __bar.foo {
358358
article {
359359
color: green;
360360

361-
/*
362-
NOTE : We are more forgiving than the spec
363-
This declaration is preserved
364-
*/
365361
color: red;
366362
}
367363
article {
@@ -371,10 +367,6 @@ article {
371367
article {
372368
color: green;
373369

374-
/*
375-
NOTE : We are more forgiving than the spec
376-
This declaration is preserved
377-
*/
378370
color: red;
379371
}
380372

@@ -387,3 +379,22 @@ article.foo {
387379
}
388380

389381
/* valid! */
382+
383+
::after, .foo {
384+
color: green;
385+
386+
color: red;
387+
388+
color: orange;
389+
}
390+
391+
::after, .foo {
392+
color: blue;
393+
}
394+
395+
@media screen {
396+
397+
::after, .foo {
398+
color: purple;
399+
}
400+
}

0 commit comments

Comments
 (0)