Skip to content
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
514 changes: 231 additions & 283 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/postcss-tape/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
// https://github.com/postcss/postcss/blob/main/docs/guidelines/plugin.md#54-include-postcss-plugin-keyword-in-packagejson
// Include postcss-plugin keyword in package.json
const packageInfo = JSON.parse(fs.readFileSync('./package.json').toString());
if (!packageInfo.keywords.includes('postcss-plugin')) {
if (!packageInfo.keywords || !packageInfo.keywords.includes('postcss-plugin')) {
hasErrors = true;

if (emitGitHubAnnotations) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export default function getOptionsForBrowsersByFeature(browsers, feature, cssdb)
const supportedBrowsers = browserslist(browsers, { ignoreUnknownVersions: true });

switch (feature.id) {
case 'is-pseudo-class':
// Emit a warning to avoid making unresolved removal of `:is()` a feature.
// see : https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-is-pseudo-class#%EF%B8%8F-known-shortcomings
return {
onComplexSelector: 'warning',
};
case 'nesting-rules':
{
// Nesting rules can transform selectors to use :is pseudo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@
order: 27;
}

.a.c > .b + .d {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@
order: 27;
}

.a.c > .b + .d {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
4 changes: 4 additions & 0 deletions plugin-packs/postcss-preset-env/test/basic.ch38.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@
order: 27;
}

.a.c > .b + .d {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
order: 27;
}

.a.c > .b + .d {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
order: 27;
}

:is(.a > .b) + :is(.c > .d) {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
order: 27;
}

:is(.a > .b) + :is(.c > .d) {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
4 changes: 4 additions & 0 deletions plugin-packs/postcss-preset-env/test/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@
order: 27;
}

:is(.a > .b) + :is(.c > .d) {
order: 28;
}

.test-hwb-function {
background-color: hwb(194 0% 0% / .5);
}
Expand Down
4 changes: 4 additions & 0 deletions plugin-packs/postcss-preset-env/test/basic.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@
order: 27;
}

.a.c > .b + .d {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
4 changes: 4 additions & 0 deletions plugin-packs/postcss-preset-env/test/basic.ff49.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@
order: 27;
}

.a.c > .b + .d {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
4 changes: 4 additions & 0 deletions plugin-packs/postcss-preset-env/test/basic.ff66.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@
order: 27;
}

.a.c > .b + .d {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
5 changes: 5 additions & 0 deletions plugin-packs/postcss-preset-env/test/basic.ie10.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@
order: 27;
}

.a.c > .b + .d {
-ms-flex-order: 28;
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
order: 27;
}

.a.c > .b + .d {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
order: 27;
}

:is(.a > .b) + :is(.c > .d) {
order: 28;
}

.test-hwb-function {
background-color: hwb(194 0% 0% / .5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,22 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
order: 27;
}

.a.c > .b + .d {
-webkit-box-ordinal-group: 29;
-webkit-order: 28;
-moz-box-ordinal-group: 29;
-ms-flex-order: 28;
order: 28;
}

:is(.a > .b) + :is(.c > .d) {
-webkit-box-ordinal-group: 29;
-webkit-order: 28;
-moz-box-ordinal-group: 29;
-ms-flex-order: 28;
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
background-color: hwb(194 0% 0% / .5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
order: 27;
}

:is(.a > .b) + :is(.c > .d) {
order: 28;
}

.test-hwb-function {
background-color: hwb(194 0% 0% / .5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
order: 27;
}

.a.c > .b + .d {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
order: 27;
}

.a.c > .b + .d {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
4 changes: 4 additions & 0 deletions plugin-packs/postcss-preset-env/test/basic.stage0.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.te
order: 27;
}

.a.c > .b + .d {
order: 28;
}

.test-hwb-function {
background-color: rgba(0, 195, 255, .5);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
import postcssTape from '../../packages/postcss-tape/dist/index.mjs';
import plugin from '@csstools/postcss-is-pseudo-class';

postcssTape(plugin)({
basic: {
message: "supports basic usage",
options: {
oncomplex: 'ignore'
}
},
'basic:preserve': {
message: "supports basic usage with { preserve: true }",
Expand All @@ -19,17 +19,11 @@ module.exports = {
},
'basic:oncomplex:warning': {
message: "supports basic usage with { onComplexSelector: 'warning' }",
warnings: 3,
warnings: 8,
options: {
onComplexSelector: 'warning'
}
},
'basic:oncomplex:skip': {
message: "supports basic usage with { onComplexSelector: 'skip' }",
options: {
onComplexSelector: 'skip'
}
},
'generated-selector-class-function-cases': {
message: "supports generated selector class function cases",
warnings: 1,
Expand All @@ -40,4 +34,4 @@ module.exports = {
example: {
message: "minimal example",
},
};
});
8 changes: 8 additions & 0 deletions plugins/postcss-is-pseudo-class/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changes to PostCSS Is Pseudo Class

### Unreleased (major)

- Remove `skip` flag in `onComplexSelectors` option.

If a complex selector is encountered that has no known equivalent, it will always be skipped and preserved now.

The previous behavior was to remove `:is()` even if that broke the selector.

### 1.0.1 (January 17, 2022)

- Fix selector order
Expand Down
8 changes: 0 additions & 8 deletions plugins/postcss-is-pseudo-class/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,6 @@ button:not(.something-random):hover {

### onComplexSelector

Do not transform complex selectors in `:is` pseudo classes.

```js
postcss([
postcssIsPseudoClass({ onComplexSelector: 'skip' })
]).process(YOUR_CSS /*, processOptions */);
```

Warn on complex selectors in `:is` pseudo classes.

```js
Expand Down
17 changes: 12 additions & 5 deletions plugins/postcss-is-pseudo-class/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,26 @@
"lint": "eslint ./src --ext .js --ext .ts --ext .mjs --no-error-on-unmatched-pattern",
"prepublishOnly": "npm run clean && npm run build && npm run test",
"stryker": "stryker run --logLevel error",
"test": "postcss-tape --ci && npm run test:exports",
"test": "node .tape.mjs && npm run test:exports",
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs",
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
},
"dependencies": {
"postcss-selector-parser": "^6.0.8"
},
"devDependencies": {
"postcss": "^8.3.6",
"postcss-tape": "^6.0.1"
},
"peerDependencies": {
"postcss": "^8.3"
},
"keywords": [
"postcss",
"css",
"postcss-plugin",
"matches",
"is",
"selector",
"polyfill",
"pseudo"
],
"repository": {
"type": "git",
"url": "https://github.com/csstools/postcss-plugins.git",
Expand Down
9 changes: 7 additions & 2 deletions plugins/postcss-is-pseudo-class/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PluginCreator } from 'postcss';
import splitSelectors from './split-selectors/split-selectors';

const creator: PluginCreator<{ preserve?: boolean, onComplexSelector?: 'warning' | 'skip', specificityMatchingName?: string }> = (opts?: { preserve?: boolean, onComplexSelector?: 'warning' | 'skip', specificityMatchingName?: string }) => {
const creator: PluginCreator<{ preserve?: boolean, onComplexSelector?: 'warning', specificityMatchingName?: string }> = (opts?: { preserve?: boolean, onComplexSelector?: 'warning', specificityMatchingName?: string }) => {
const options = {
specificityMatchingName: 'does-not-exist',
...(opts || {}),
Expand Down Expand Up @@ -29,7 +29,7 @@ const creator: PluginCreator<{ preserve?: boolean, onComplexSelector?: 'warning'
}

didWarn = true;
rule.warn(result, `Complex selectors in '${rule.selector}' will have different matching after transforming.`);
rule.warn(result, `Complex selectors in '${rule.selector}' can not be transformed to an equivalent selector without ':is()'.`);
};

try {
Expand Down Expand Up @@ -61,6 +61,11 @@ const creator: PluginCreator<{ preserve?: boolean, onComplexSelector?: 'warning'
rule.remove();
}
} catch (e) {
// Do not ignore infinite recursion errors.
if (e.message.indexOf('call stack size exceeded') > -1) {
throw e;
}

rule.warn(result, `Failed to parse selector "${rule.selector}"`);
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Some patterns can be detected and converted.
This is very difficult to abstract, so best to handle this case by case on request.

Make each case a separate file and write a very specific matcher.
Loading