Skip to content

Commit c497cd4

Browse files
authored
postcss-nesting : preserve semicolon (#498)
* postcss-nesting : preserve semicolon * deno tests
1 parent 8f4ab65 commit c497cd4

37 files changed

+276
-215
lines changed

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
@@ -503,5 +503,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
503503
}
504504

505505
[data-view-size=m] .view {
506-
background: red
506+
background: red;
507507
}

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
@@ -477,5 +477,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
477477
}
478478

479479
[data-view-size=m] .view {
480-
background: red
480+
background: red;
481481
}

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
@@ -477,5 +477,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
477477
}
478478

479479
[data-view-size=m] .view {
480-
background: red
480+
background: red;
481481
}

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
@@ -405,5 +405,5 @@
405405
@custom-selector :--view-m [data-view-size=m];
406406

407407
:--view-m .view {
408-
background: red
408+
background: red;
409409
}

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
@@ -594,5 +594,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
594594
}
595595

596596
[data-view-size=m] .view {
597-
background: red
597+
background: red;
598598
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,9 +1023,9 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
10231023
@custom-selector :--view-m [data-view-size=m];
10241024

10251025
[data-view-size=m] .view {
1026-
background: red
1026+
background: red;
10271027
}
10281028

10291029
:--view-m .view {
1030-
background: red
1030+
background: red;
10311031
}

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
@@ -505,5 +505,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
505505
}
506506

507507
[data-view-size=m] .view {
508-
background: red
508+
background: red;
509509
}

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
@@ -490,5 +490,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
490490
}
491491

492492
[data-view-size=m] .view {
493-
background: red
493+
background: red;
494494
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,5 +616,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
616616
}
617617

618618
[data-view-size=m] .view {
619-
background: red
619+
background: red;
620620
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-webkit-order: 5.1;
77
-moz-box-ordinal-group: 6;
88
-ms-flex-order: 5.1;
9-
order: 5.1
9+
order: 5.1;
1010
}
1111

1212
:root:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
@@ -54,11 +54,11 @@
5454
}
5555

5656
[dir="ltr"] .test-logical-properties-and-values:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#){
57-
margin: 1px 4px 3px 2px
57+
margin: 1px 4px 3px 2px;
5858
}
5959

6060
[dir="rtl"] .test-logical-properties-and-values:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#){
61-
margin: 1px 2px 3px 4px
61+
margin: 1px 2px 3px 4px;
6262
}
6363

6464
.test-logical-properties-and-values:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
@@ -87,7 +87,7 @@
8787
-webkit-order: 5;
8888
-moz-box-ordinal-group: 6;
8989
-ms-flex-order: 5;
90-
order: 5
90+
order: 5;
9191
}
9292

9393
.test-nesting-rules:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
-webkit-order: 5.1;
77
-moz-box-ordinal-group: 6;
88
-ms-flex-order: 5.1;
9-
order: 5.1
9+
order: 5.1;
1010
}
1111

1212
:root:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
@@ -60,19 +60,19 @@
6060
}
6161

6262
[dir="ltr"] .test-logical-properties-and-values:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#){
63-
margin: 1px 4px 3px 2px
63+
margin: 1px 4px 3px 2px;
6464
}
6565

6666
.test-logical-properties-and-values:dir(ltr):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#){
67-
margin: 1px 4px 3px 2px
67+
margin: 1px 4px 3px 2px;
6868
}
6969

7070
[dir="rtl"] .test-logical-properties-and-values:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#){
71-
margin: 1px 2px 3px 4px
71+
margin: 1px 2px 3px 4px;
7272
}
7373

7474
.test-logical-properties-and-values:dir(rtl):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#){
75-
margin: 1px 2px 3px 4px
75+
margin: 1px 2px 3px 4px;
7676
}
7777

7878
.test-logical-properties-and-values:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
@@ -103,7 +103,7 @@
103103
-webkit-order: 5;
104104
-moz-box-ordinal-group: 6;
105105
-ms-flex-order: 5;
106-
order: 5
106+
order: 5;
107107
}
108108

109109
.test-nesting-rules:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {

plugins/postcss-nesting/CHANGELOG.md

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

3+
### Unreleased
4+
5+
- Fix semicolons being removed (https://github.com/csstools/postcss-plugins/issues/497).
6+
37
### 10.1.8 (June 4, 2022)
48

59
- Update `@csstools/selector-specificity` (major)

plugins/postcss-nesting/src/lib/nest-rule-within-rule.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default function transformNestRuleWithinRule(node, walk, opts) {
99

1010
// clone the parent as a new rule with children appended to it
1111
const rule = parent.clone().removeAll().append(node.nodes);
12+
rule.raws.semicolon = true; /* nested rules end with "}" and do not have this flag set */
1213

1314
// replace the node with the new rule
1415
node.replaceWith(rule);

plugins/postcss-nesting/src/lib/shift-nodes-before-parent.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ export default function shiftNodesBeforeParent(node) {
77
// conditionally move previous siblings into a clone of the parent
88
if (index) {
99
const newParent = parent.cloneBefore().removeAll().append(parent.nodes.slice(0, index));
10+
newParent.raws.semicolon = true; /* nested rules end with "}" and do not have this flag set */
1011
cleanupParent(newParent);
1112
}
1213

1314
// move the current node before the parent (and after the conditional clone)
1415
parent.before(node);
16+
parent.raws.semicolon = true; /* nested rules end with "}" and do not have this flag set */
1517

1618
return parent;
1719
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
11
a {
2-
order: 1
2+
order: 1;
33
}
44
b a {
5-
order: 2
5+
order: 2;
66
}
77
c a {
8-
order: 3
8+
order: 3;
99
}
1010
d a {
11-
order: 4
11+
order: 4;
1212
}
1313
e a {
14-
order: 5
14+
order: 5;
1515
}
1616
a {
17-
order: 1
17+
order: 1;
1818
}
1919
a b {
20-
order: 2
20+
order: 2;
2121
}
2222
a c {
23-
order: 3
23+
order: 3;
2424
}
2525
a d {
26-
order: 4
26+
order: 4;
2727
}
2828
a e {
29-
order: 5
29+
order: 5;
3030
}
3131
a[foo="& ,\'"] {
32-
order: 6
32+
order: 6;
3333
}
3434
a[a="& ,\'"][b='& . \\a &'] {
35-
order: 7
35+
order: 7;
3636
}
3737
a:is(\\foo) {
38-
order: 8
38+
order: 8;
3939
}
4040

4141
h1.foo {
42-
color: red
42+
color: red;
4343
}
4444

4545
h1.foo, h2.foo {
46-
color: red
46+
color: red;
4747
}
4848

4949
.foo.bar {
50-
color: red
50+
color: red;
5151
}
5252

5353

5454
.foo.bar, .foo.baz {
55-
color: red
55+
color: red;
5656
}
5757

5858
h1.foo {
59-
color: blue
59+
color: blue;
6060
}
6161

6262
h1.foo .baz h1 {
63-
color: blue
63+
color: blue;
6464
}
6565

6666
h1.foo, h1.bar {
67-
color: blue
67+
color: blue;
6868
}
6969

7070
article {
71-
color: blue
71+
color: blue;
7272
}
7373

7474
:where(article) {
75-
color: red
75+
color: red;
7676
}
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,76 @@
11
a {
2-
order: 1
2+
order: 1;
33
}
44
b a {
5-
order: 2
5+
order: 2;
66
}
77
c a {
8-
order: 3
8+
order: 3;
99
}
1010
d a {
11-
order: 4
11+
order: 4;
1212
}
1313
e a {
14-
order: 5
14+
order: 5;
1515
}
1616
a {
17-
order: 1
17+
order: 1;
1818
}
1919
a b {
20-
order: 2
20+
order: 2;
2121
}
2222
a c {
23-
order: 3
23+
order: 3;
2424
}
2525
a d {
26-
order: 4
26+
order: 4;
2727
}
2828
a e {
29-
order: 5
29+
order: 5;
3030
}
3131
a[foo="& ,\'"] {
32-
order: 6
32+
order: 6;
3333
}
3434
a[a="& ,\'"][b='& . \\a &'] {
35-
order: 7
35+
order: 7;
3636
}
3737
a\\foo {
38-
order: 8
38+
order: 8;
3939
}
4040

4141
h1.foo {
42-
color: red
42+
color: red;
4343
}
4444

4545
h1.foo, h2.foo {
46-
color: red
46+
color: red;
4747
}
4848

4949
.foo.bar {
50-
color: red
50+
color: red;
5151
}
5252

5353

5454
.foo.bar, .foo.baz {
55-
color: red
55+
color: red;
5656
}
5757

5858
h1.foo {
59-
color: blue
59+
color: blue;
6060
}
6161

6262
h1.foo .baz h1 {
63-
color: blue
63+
color: blue;
6464
}
6565

6666
h1.foo, h1.bar {
67-
color: blue
67+
color: blue;
6868
}
6969

7070
article {
71-
color: blue
71+
color: blue;
7272
}
7373

7474
:where(article) {
75-
color: red
75+
color: red;
7676
}

plugins/postcss-nesting/test/basic.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,21 @@ a {
155155
order: 72;
156156
}
157157
}
158+
159+
.has-semi-colons-on-the-last-decl {
160+
order: 73;
161+
/* a comment */
162+
163+
& .foo {
164+
order: 73.1;
165+
}
166+
}
167+
168+
.has-semi-colons-on-the-last-decl {
169+
order: 74;
170+
/* a comment */
171+
172+
@nest & .foo {
173+
order: 74.1;
174+
}
175+
}

0 commit comments

Comments
 (0)