Skip to content

postcss-nesting : preserve semicolon #498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -503,5 +503,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
}

[data-view-size=m] .view {
background: red
background: red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -477,5 +477,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
}

[data-view-size=m] .view {
background: red
background: red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -477,5 +477,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
}

[data-view-size=m] .view {
background: red
background: red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -405,5 +405,5 @@
@custom-selector :--view-m [data-view-size=m];

:--view-m .view {
background: red
background: red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -594,5 +594,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
}

[data-view-size=m] .view {
background: red
background: red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1023,9 +1023,9 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
@custom-selector :--view-m [data-view-size=m];

[data-view-size=m] .view {
background: red
background: red;
}

:--view-m .view {
background: red
background: red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -505,5 +505,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
}

[data-view-size=m] .view {
background: red
background: red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -490,5 +490,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
}

[data-view-size=m] .view {
background: red
background: red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -616,5 +616,5 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
}

[data-view-size=m] .view {
background: red
background: red;
}
8 changes: 4 additions & 4 deletions plugin-packs/postcss-preset-env/test/layers-basic.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-webkit-order: 5.1;
-moz-box-ordinal-group: 6;
-ms-flex-order: 5.1;
order: 5.1
order: 5.1;
}

:root:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
Expand Down Expand Up @@ -54,11 +54,11 @@
}

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

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

.test-logical-properties-and-values:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
Expand Down Expand Up @@ -87,7 +87,7 @@
-webkit-order: 5;
-moz-box-ordinal-group: 6;
-ms-flex-order: 5;
order: 5
order: 5;
}

.test-nesting-rules:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-webkit-order: 5.1;
-moz-box-ordinal-group: 6;
-ms-flex-order: 5.1;
order: 5.1
order: 5.1;
}

:root:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
Expand Down Expand Up @@ -60,19 +60,19 @@
}

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

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

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

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

.test-logical-properties-and-values:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
Expand Down Expand Up @@ -103,7 +103,7 @@
-webkit-order: 5;
-moz-box-ordinal-group: 6;
-ms-flex-order: 5;
order: 5
order: 5;
}

.test-nesting-rules:not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#):not(#\#) {
Expand Down
4 changes: 4 additions & 0 deletions plugins/postcss-nesting/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes to PostCSS Nesting

### Unreleased

- Fix semicolons being removed (https://github.com/csstools/postcss-plugins/issues/497).

### 10.1.8 (June 4, 2022)

- Update `@csstools/selector-specificity` (major)
Expand Down
1 change: 1 addition & 0 deletions plugins/postcss-nesting/src/lib/nest-rule-within-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default function transformNestRuleWithinRule(node, walk, opts) {

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

// replace the node with the new rule
node.replaceWith(rule);
Expand Down
2 changes: 2 additions & 0 deletions plugins/postcss-nesting/src/lib/shift-nodes-before-parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ export default function shiftNodesBeforeParent(node) {
// conditionally move previous siblings into a clone of the parent
if (index) {
const newParent = parent.cloneBefore().removeAll().append(parent.nodes.slice(0, index));
newParent.raws.semicolon = true; /* nested rules end with "}" and do not have this flag set */
cleanupParent(newParent);
}

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

return parent;
}
44 changes: 22 additions & 22 deletions plugins/postcss-nesting/test/at-rule.expect.css
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
a {
order: 1
order: 1;
}
b a {
order: 2
order: 2;
}
c a {
order: 3
order: 3;
}
d a {
order: 4
order: 4;
}
e a {
order: 5
order: 5;
}
a {
order: 1
order: 1;
}
a b {
order: 2
order: 2;
}
a c {
order: 3
order: 3;
}
a d {
order: 4
order: 4;
}
a e {
order: 5
order: 5;
}
a[foo="& ,\'"] {
order: 6
order: 6;
}
a[a="& ,\'"][b='& . \\a &'] {
order: 7
order: 7;
}
a:is(\\foo) {
order: 8
order: 8;
}

h1.foo {
color: red
color: red;
}

h1.foo, h2.foo {
color: red
color: red;
}

.foo.bar {
color: red
color: red;
}


.foo.bar, .foo.baz {
color: red
color: red;
}

h1.foo {
color: blue
color: blue;
}

h1.foo .baz h1 {
color: blue
color: blue;
}

h1.foo, h1.bar {
color: blue
color: blue;
}

article {
color: blue
color: blue;
}

:where(article) {
color: red
color: red;
}
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
a {
order: 1
order: 1;
}
b a {
order: 2
order: 2;
}
c a {
order: 3
order: 3;
}
d a {
order: 4
order: 4;
}
e a {
order: 5
order: 5;
}
a {
order: 1
order: 1;
}
a b {
order: 2
order: 2;
}
a c {
order: 3
order: 3;
}
a d {
order: 4
order: 4;
}
a e {
order: 5
order: 5;
}
a[foo="& ,\'"] {
order: 6
order: 6;
}
a[a="& ,\'"][b='& . \\a &'] {
order: 7
order: 7;
}
a\\foo {
order: 8
order: 8;
}

h1.foo {
color: red
color: red;
}

h1.foo, h2.foo {
color: red
color: red;
}

.foo.bar {
color: red
color: red;
}


.foo.bar, .foo.baz {
color: red
color: red;
}

h1.foo {
color: blue
color: blue;
}

h1.foo .baz h1 {
color: blue
color: blue;
}

h1.foo, h1.bar {
color: blue
color: blue;
}

article {
color: blue
color: blue;
}

:where(article) {
color: red
color: red;
}
18 changes: 18 additions & 0 deletions plugins/postcss-nesting/test/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,21 @@ a {
order: 72;
}
}

.has-semi-colons-on-the-last-decl {
order: 73;
/* a comment */

& .foo {
order: 73.1;
}
}

.has-semi-colons-on-the-last-decl {
order: 74;
/* a comment */

@nest & .foo {
order: 74.1;
}
}
Loading