Skip to content
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

fix: fixed merging of unsupported pseudos by caniuse and browserlist #883

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions packages/cssnano/src/__tests__/postcss-merge-rules.js
@@ -1,4 +1,4 @@
import processCss from './_processCss';
import processCss, { passthrough } from './_processCss';

test(
'should merge based on declarations',
Expand Down Expand Up @@ -183,9 +183,8 @@ test(

test(
'should merge vendor prefixed selectors when vendors are the same',
processCss(
'code ::-moz-selection{background:red}code::-moz-selection{background:red}',
'code::-moz-selection,code ::-moz-selection{background:red}'
passthrough(
'code ::-moz-selection{background:red}code::-moz-selection{background:red}'
)
);

Expand Down
17 changes: 14 additions & 3 deletions packages/postcss-merge-rules/src/__tests__/index.js
Expand Up @@ -251,9 +251,20 @@ test(

test(
'should merge vendor prefixed selectors when vendors are the same',
processCSS(
'code ::-moz-selection{background:red}code::-moz-selection{background:red}',
'code ::-moz-selection,code::-moz-selection{background:red}'
passthroughCSS(
'code ::-moz-selection{background:red}code::-moz-selection{background:red}'
)
);

test(
'should not merge pseudo which are not supported by the browsers ::selection',
passthroughCSS('::selection{background:red} ::selection{background:red}')
);

test(
'should not merge pseudo which are not supported by the browsers - code ::selection',
passthroughCSS(
'code ::selection{background:red} code ::selection{background:red}'
)
);

Expand Down
8 changes: 6 additions & 2 deletions packages/postcss-merge-rules/src/lib/ensureCompatibility.js
@@ -1,3 +1,4 @@
import postcss from 'postcss';
import { isSupported } from 'caniuse-api';
import selectorParser from 'postcss-selector-parser';

Expand Down Expand Up @@ -55,6 +56,7 @@ export const pseudoElements = {
'::marker': 'css-marker-pseudo',
'::placeholder': 'css-placeholder',
'::selection': 'css-selection',
':visited': cssSel3,
};

function isCssMixin(selector) {
Expand Down Expand Up @@ -97,8 +99,10 @@ export default function ensureCompatibility(
ast.walk((node) => {
const { type, value } = node;
if (type === 'pseudo') {
const entry = pseudoElements[value];
if (entry && compatible) {
const entry = pseudoElements[postcss.vendor.unprefixed(value)];
if (!entry) {
compatible = false;
} else if (compatible) {
compatible = isSupportedCached(entry, browsers);
}
}
Expand Down