Skip to content

Commit b4220ea

Browse files
authored
nesting : latest specification (#996)
* nesting : latest specification * changelogs * add docs for silence option and link to stylelint plugin
1 parent 5eda268 commit b4220ea

File tree

69 files changed

+4440
-570
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+4440
-570
lines changed

plugin-packs/postcss-preset-env/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes to PostCSS Preset Env
22

3+
### Unreleased (minor)
4+
5+
- Add warning when using the deprecated `@nest` rule
6+
37
### 8.4.2 (June 1, 2023)
48

59
- Updated `@csstools/postcss-progressive-custom-properties` to `2.3.0` (minor)

plugin-packs/postcss-preset-env/test/basic.autoprefixer.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@
525525

526526
:--view-m .view {
527527
background: red;
528-
}
528+
}
529529

530530
.nested-calc {
531531
order: calc(1 * (8 / 3 + (5 * 10)));

plugin-packs/postcss-preset-env/test/basic.autoprefixer.false.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@
525525

526526
:--view-m .view {
527527
background: red;
528-
}
528+
}
529529

530530
.nested-calc {
531531
order: calc(1 * (8 / 3 + (5 * 10)));

plugin-packs/postcss-preset-env/test/basic.ch38.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@
435435

436436
:--view-m .view {
437437
background: red;
438-
}
438+
}
439439

440440
.nested-calc {
441441
order: calc(1 * (8 / 3 + (5 * 10)));

plugin-packs/postcss-preset-env/test/basic.ch88-ff78-saf10.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ h1.test-custom-selectors:not(.does-not-exist), h2.test-custom-selectors:not(.doe
432432

433433
[data-view-size=m] .view {
434434
background: red;
435-
}
435+
}
436436

437437
.nested-calc {
438438
order: calc(1 * (8 / 3 + (5 * 10)));

plugin-packs/postcss-preset-env/test/basic.ch88-ff78.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ h1.test-custom-selectors:not(.does-not-exist), h2.test-custom-selectors:not(.doe
432432

433433
[data-view-size=m] .view {
434434
background: red;
435-
}
435+
}
436436

437437
.nested-calc {
438438
order: calc(1 * calc(8 / 3 + calc(5 * 10)));

plugin-packs/postcss-preset-env/test/basic.ch88-ff78.no-is-pseudo.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ h1.test-custom-selectors:not(.does-not-exist), h2.test-custom-selectors:not(.doe
432432

433433
[data-view-size=m] .view {
434434
background: red;
435-
}
435+
}
436436

437437
.nested-calc {
438438
order: calc(1 * calc(8 / 3 + calc(5 * 10)));

plugin-packs/postcss-preset-env/test/basic.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@
402402
@custom-selector :--view-m [data-view-size=m];
403403

404404
.view {
405-
@nest :--view-m & {
405+
:--view-m & {
406406
background: red;
407407
}
408408
}

plugin-packs/postcss-preset-env/test/basic.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@
542542

543543
:--view-m .view {
544544
background: red;
545-
}
545+
}
546546

547547
.nested-calc {
548548
order: calc(1 * (8 / 3 + (5 * 10)));

plugin-packs/postcss-preset-env/test/basic.ff49.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@
438438

439439
:--view-m .view {
440440
background: red;
441-
}
441+
}
442442

443443
.nested-calc {
444444
order: calc(1 * calc(8 / 3 + calc(5 * 10)));

plugin-packs/postcss-preset-env/test/basic.ff66.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@
433433

434434
:--view-m .view {
435435
background: red;
436-
}
436+
}
437437

438438
.nested-calc {
439439
order: calc(1 * calc(8 / 3 + calc(5 * 10)));

plugin-packs/postcss-preset-env/test/basic.hebrew.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ h1.test-custom-selectors:not(.does-not-exist), h2.test-custom-selectors:not(.doe
538538

539539
[data-view-size=m] .view {
540540
background: red;
541-
}
541+
}
542542

543543
.nested-calc {
544544
order: calc(1 * (8 / 3 + (5 * 10)));

plugin-packs/postcss-preset-env/test/basic.ie10.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@
559559

560560
:--view-m .view {
561561
background: red;
562-
}
562+
}
563563

564564
.nested-calc {
565565
-ms-flex-order: calc(1 * (8 / 3 + (5 * 10)));

plugin-packs/postcss-preset-env/test/basic.nesting.false.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ h1.test-custom-selectors:not(.does-not-exist), h2.test-custom-selectors:not(.doe
537537
}
538538

539539
.view {
540-
@nest :--view-m & {
540+
[data-view-size=m] & {
541541
background: red;
542542
}
543543
}

plugin-packs/postcss-preset-env/test/basic.nesting.true.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@
410410

411411
:--view-m .view {
412412
background: red;
413-
}
413+
}
414414

415415
.nested-calc {
416416
order: calc(1 * calc(8 / 3 + calc(5 * 10)));

plugin-packs/postcss-preset-env/test/basic.op_mini.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ h1.test-custom-selectors:not(.does-not-exist), h2.test-custom-selectors:not(.doe
522522

523523
[data-view-size=m] .view {
524524
background: red;
525-
}
525+
}
526526

527527
.nested-calc {
528528
order: calc(1 * (8 / 3 + (5 * 10)));

plugin-packs/postcss-preset-env/test/basic.preserve.false.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ h1.test-custom-selectors:not(.does-not-exist), h2.test-custom-selectors:not(.doe
661661

662662
[data-view-size=m] .view {
663663
background: red;
664-
}
664+
}
665665

666666
.nested-calc {
667667
-webkit-box-ordinal-group: NaN;

plugin-packs/postcss-preset-env/test/basic.preserve.true.expect.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,15 +891,15 @@ h1.test-custom-selectors:not(.does-not-exist), h2.test-custom-selectors:not(.doe
891891

892892
[data-view-size=m] .view {
893893
background: red;
894-
}
894+
}
895895

896896
:is([data-view-size=m]) .view {
897897
background: red;
898-
}
898+
}
899899

900900
:--view-m .view {
901901
background: red;
902-
}
902+
}
903903

904904
.nested-calc {
905905
-webkit-box-ordinal-group: NaN;

plugin-packs/postcss-preset-env/test/basic.safari15.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@
414414

415415
:--view-m .view {
416416
background: red;
417-
}
417+
}
418418

419419
.nested-calc {
420420
order: calc(1 * calc(8 / 3 + calc(5 * 10)));

plugin-packs/postcss-preset-env/test/basic.stage0-ff49.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ h1.test-custom-selectors:not(.does-not-exist), h2.test-custom-selectors:not(.doe
434434

435435
[data-view-size=m] .view {
436436
background: red;
437-
}
437+
}
438438

439439
.nested-calc {
440440
order: calc(1 * calc(8 / 3 + calc(5 * 10)));

plugin-packs/postcss-preset-env/test/basic.stage0-ff66.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ h1.test-custom-selectors:not(.does-not-exist), h2.test-custom-selectors:not(.doe
429429

430430
[data-view-size=m] .view {
431431
background: red;
432-
}
432+
}
433433

434434
.nested-calc {
435435
order: calc(1 * calc(8 / 3 + calc(5 * 10)));

plugin-packs/postcss-preset-env/test/basic.stage0.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ h1.test-custom-selectors:not(.does-not-exist), h2.test-custom-selectors:not(.doe
538538

539539
[data-view-size=m] .view {
540540
background: red;
541-
}
541+
}
542542

543543
.nested-calc {
544544
order: calc(1 * (8 / 3 + (5 * 10)));

plugin-packs/postcss-preset-env/test/basic.vendors-1.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@
545545
@custom-selector :--view-m [data-view-size=m];
546546

547547
.view {
548-
@nest :--view-m & {
548+
:--view-m & {
549549
background: red;
550550
}
551551
}

plugin-packs/postcss-preset-env/test/basic.vendors-2.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@
545545
@custom-selector :--view-m [data-view-size=m];
546546

547547
.view {
548-
@nest :--view-m & {
548+
:--view-m & {
549549
background: red;
550550
}
551551
}

plugin-packs/postcss-preset-env/test/basic.vendors-3.expect.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@
517517
@custom-selector :--view-m [data-view-size=m];
518518

519519
.view {
520-
@nest :--view-m & {
520+
:--view-m & {
521521
background: red;
522522
}
523523
}

plugins/postcss-nesting/.tape.mjs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,20 @@ postcssTape(plugin)({
5858
noIsPseudoSelector: true,
5959
},
6060
},
61-
'at-rule': {
62-
message: 'supports at-rule usage',
61+
'at-nest': {
62+
message: 'supports at-nest usage',
63+
warnings: 64,
6364
},
64-
'at-rule:no-is-pseudo-selector': {
65-
message: 'supports at-rule usage { noIsPseudoSelector: true }',
65+
'at-nest:silent': {
66+
message: 'supports at-nest usage { silenceAtNestWarning: true }',
67+
warnings: 4,
68+
options: {
69+
silenceAtNestWarning: true,
70+
}
71+
},
72+
'at-nest:no-is-pseudo-selector': {
73+
message: 'supports at-nest usage { noIsPseudoSelector: true }',
74+
warnings: 64,
6675
options: {
6776
noIsPseudoSelector: true,
6877
},
@@ -130,14 +139,12 @@ postcssTape(plugin)({
130139
},
131140
'ignore': {
132141
message: 'ignores invalid entries',
133-
warnings: 1
134142
},
135143
'ignore:no-is-pseudo-selector': {
136144
message: 'ignores invalid entries { noIsPseudoSelector: true }',
137145
options: {
138146
noIsPseudoSelector: true,
139147
},
140-
warnings: 1
141148
},
142149
'mixin-declaration': {
143150
message: 'supports other visitors (mixin declaration)',

plugins/postcss-nesting/CHANGELOG.md

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

3+
### Unreleased (minor)
4+
5+
- Add support for nested selectors that that begin with a letter
6+
- Add warning when using the deprecated `@nest` rule
7+
- you can silence this warning with a new `silenceAtNestWarning` plugin option
8+
- you can migrate your code to the latest syntax with our [Stylelint Plugin](https://github.com/csstools/postcss-plugins/tree/main/plugins-stylelint/no-at-nest-rule#csstoolsstylelint-no-at-nest-rule)
9+
310
### 11.2.2 (March 25, 2023)
411

512
- Improved: support for mixins

plugins/postcss-nesting/README.md

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,39 +77,21 @@ instructions for:
7777
Previous iterations of the [CSS Nesting specification] required using `@nest` for certain selectors.
7878

7979
`@nest` was removed from the specification completely.
80-
Future versions of this plugin will first warn and then error if you use `@nest`.
80+
Future versions of this plugin will error if you use `@nest`.
8181

82-
We advice everyone to migrate their codebase **now** to nested CSS without `@nest`.
82+
We advice everyone to migrate their codebase **now** to nested CSS without `@nest`.
83+
We published a [Stylelint Plugin](https://github.com/csstools/postcss-plugins/tree/main/plugins-stylelint/no-at-nest-rule#csstoolsstylelint-no-at-nest-rule) to help you migrate.
8384

84-
## ⚠️ Nested selectors must start with a symbol
85+
example warning:
86+
> `@nest` was removed from the CSS Nesting specification and will be removed from PostCSS Nesting in the next major version.
87+
> Change `@nest foo & {}` to `foo & {}` to migrate to the latest standard.
8588
86-
The current version of the [CSS Nesting specification](https://www.w3.org/TR/2023/WD-css-nesting-1-20230214/#example-34e8e94f) disallows nested selectors to start with a letter (i.e. a tag name or element selector). To write such selectors, they need to be prefixed with `& ` or wrapped with `:is()`.
89+
You can silence this warning with a new `silenceAtNestWarning` plugin option.
8790

88-
You will get a warning when selectors start with a letter:
89-
> Nested selectors must start with a symbol and "span" begins with a letter.
90-
91-
```pcss
92-
.foo {
93-
/* ❌ invalid */
94-
span {
95-
color: hotpink;
96-
}
97-
98-
/* ✅ valid */
99-
& span {
100-
color: hotpink;
101-
}
102-
103-
/* ❌ invalid */
104-
span & {
105-
color: hotpink;
106-
}
107-
108-
/* ✅ valid */
109-
:is(span) & {
110-
color: hotpink;
111-
}
112-
}
91+
```js
92+
postcssNesting({
93+
silenceAtNestWarning: true
94+
})
11395
```
11496

11597
## Options

plugins/postcss-nesting/dist/index.cjs

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

plugins/postcss-nesting/dist/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import type { PluginCreator } from 'postcss';
33
export type pluginOptions = {
44
/** Avoid the `:is()` pseudo class as much as possible. default: false */
55
noIsPseudoSelector?: boolean;
6+
/** Silence the `@nest` warning. */
7+
silenceAtNestWarning?: boolean;
68
};
79
declare const creator: PluginCreator<pluginOptions>;
810
export default creator;

plugins/postcss-nesting/dist/index.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
import { options } from '../options';
2-
import type { Node, Result } from 'postcss';
3-
export default function mergeSelectors(node: Node, postcssResult: Result, fromSelectors: Array<string>, toSelectors: Array<string>, opts: options, fromAtNest?: boolean): any[];
2+
export default function mergeSelectors(fromSelectors: Array<string>, toSelectors: Array<string>, opts: options): any[];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export type options = {
22
noIsPseudoSelector: boolean;
3+
silenceAtNestWarning: boolean;
34
};

0 commit comments

Comments
 (0)