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

test(postcss-minify-params): @supports at-rule #708

Merged
merged 1 commit into from Jan 31, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/postcss-minify-params/src/__tests__/index.js
Expand Up @@ -144,6 +144,34 @@ test(
'@supports (display:grid) {}'
);

test(
'should normalise @supports with not',
processCSS,
'@supports not (display: grid) {}',
'@supports not (display:grid) {}'
);

test(
'should normalise @supports with multiple conditions',
processCSS,
'@supports ((text-align-last: justify) or (-moz-text-align-last: justify)) {}',
'@supports ((text-align-last:justify) or (-moz-text-align-last:justify)) {}'
);

test(
'should normalise @supports with var',
processCSS,
'@supports (--foo: green) {}',
'@supports (--foo:green) {}'
);

test(
'should normalise @supports with :is',
processCSS,
'@supports not selector(:is(a, b)) {}',
'@supports not selector(:is(a,b)) {}'
);

test(
'should not throw on empty parentheses',
passthroughCSS,
Expand Down
6 changes: 6 additions & 0 deletions packages/postcss-minify-params/src/index.js
Expand Up @@ -42,6 +42,7 @@ function transform (legacy, rule) {
params.walk((node, index) => {
if (node.type === 'div' || node.type === 'function') {
node.before = node.after = '';

if (
node.type === 'function' &&
node.nodes[4] &&
Expand All @@ -51,25 +52,30 @@ function transform (legacy, rule) {
node.nodes[2].value,
node.nodes[4].value
);

node.nodes[2].value = a;
node.nodes[4].value = b;
}
} else if (node.type === 'space') {
node.value = ' ';
} else {
const prevWord = params.nodes[index - 2];

if (
node.value.toLowerCase() === 'all' &&
rule.name.toLowerCase() === 'media' &&
!prevWord
) {
const nextWord = params.nodes[index + 2];

if (!legacy || nextWord) {
removeNode(node);
}

if (nextWord && nextWord.value.toLowerCase() === 'and') {
const nextSpace = params.nodes[index + 1];
const secondSpace = params.nodes[index + 3];

removeNode(nextWord);
removeNode(nextSpace);
removeNode(secondSpace);
Expand Down