Skip to content

postcss-nesting : spec compliance #1140

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

Closed
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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugin-packs/postcss-preset-env/dist/index.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugin-packs/postcss-preset-env/dist/index.mjs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import browserslist from 'browserslist';
import { getUnsupportedBrowsersByFeature } from './get-unsupported-browsers-by-feature.mjs';

// add extra options for certain browsers by feature
export default function getOptionsForBrowsersByFeature(supportedBrowsers, feature, cssdbList, options, logger) {
switch (feature.id) {
Expand All @@ -10,25 +7,6 @@ export default function getOptionsForBrowsersByFeature(supportedBrowsers, featur
return {
onComplexSelector: 'warning',
};
case 'nesting-rules':
{
// TODO : remove this in a next major release

// Nesting rules can transform selectors to use :is pseudo.
// This is more spec compliant but it's not supported by all browsers.
// If we can't use :is pseudo according to preset-env options, we add an extra option to avoid :is pseudo.
const feature = cssdbList.find(feature => feature.id === 'is-pseudo-class');

if (needsOptionFor(feature, supportedBrowsers)) {
logger.log('Disabling :is on "nesting-rules" due to lack of browser support.');
return {
noIsPseudoSelector: true,
};
}
}

return {};

case 'any-link-pseudo-class':
{
const hasIEOrEdge = supportedBrowsers.find((browserslistEntry) => {
Expand Down Expand Up @@ -64,18 +42,3 @@ export default function getOptionsForBrowsersByFeature(supportedBrowsers, featur
return {};
}
}

function needsOptionFor(feature, supportedBrowsers) {
const unsupportedIn = getUnsupportedBrowsersByFeature(feature);
const unsupportedBrowsers = browserslist(unsupportedIn, {
ignoreUnknownVersions: true,
});

if (supportedBrowsers.some((supportedBrowser) => {
return unsupportedBrowsers.some(polyfillBrowser => polyfillBrowser === supportedBrowser);
})) {
return true;
}

return false;
}
23 changes: 0 additions & 23 deletions plugin-packs/postcss-preset-env/test/_tape.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,6 @@ postcssTape(plugin)({
browsers: 'op_mini all',
},
},
'basic:ch88-ff78:no-is-pseudo': {
message: ':is pseudo for nesting can be disable with modern browsers { browsers: "chrome >= 88, firefox >= 78", stage: 0, features: { nesting-rules: { noIsPseudoSelector: true } } } usage',
options: {
browsers: 'chrome >= 88, firefox >= 78',
stage: 0,
features: {
'nesting-rules': {
noIsPseudoSelector: true,
},
},
},
},
'basic:ch88-ff78-saf10': {
message: 'does not use :is pseudo for nesting with an older browser { browsers: "chrome >= 88, firefox >= 78, safari >= 10", stage: 0 } usage',
options: {
Expand Down Expand Up @@ -142,17 +130,6 @@ postcssTape(plugin)({
},
},
},
'basic:nesting:noIsPseudoSelector:false': {
message: 'supports { stage: false, features: { "nesting-rules": { "noIsPseudoSelector": false } } } usage',
options: {
stage: false,
features: {
'nesting-rules': {
noIsPseudoSelector: false,
},
},
},
},
'basic:nesting:false': {
message: 'supports { stage: 0, features: { "nesting-rules": false } } usage',
options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
order: 9;
}

.test-nesting-rules + p, #test-is-pseudo + p {
.test-nesting-rules:not(#does-not-exist) + p,#test-is-pseudo + p {
order: 8;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
order: 9;
}

.test-nesting-rules + p, #test-is-pseudo + p {
.test-nesting-rules:not(#does-not-exist) + p,#test-is-pseudo + p {
order: 8;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
order: 9;
}

.test-nesting-rules + p, #test-is-pseudo + p {
.test-nesting-rules:not(#does-not-exist) + p,#test-is-pseudo + p {
order: 8;
}

Expand Down
2 changes: 1 addition & 1 deletion plugin-packs/postcss-preset-env/test/basic.ch38.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
order: 9;
}

.test-nesting-rules + p, #test-is-pseudo + p {
.test-nesting-rules:not(#does-not-exist) + p,#test-is-pseudo + p {
order: 8;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
order: 9;
}

.test-nesting-rules + p, #test-is-pseudo + p {
.test-nesting-rules:not(#does-not-exist) + p,#test-is-pseudo + p {
order: 8;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
order: 9;
}

.test-nesting-rules + p, #test-is-pseudo + p {
.test-nesting-rules:not(#does-not-exist) + p,#test-is-pseudo + p {
order: 8;
}

Expand Down
Loading