Skip to content

Commit

Permalink
test(postcss-minify-params): @supports at-rule (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Jan 31, 2019
1 parent acd5d0e commit 159922a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
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

0 comments on commit 159922a

Please sign in to comment.