Skip to content
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
27 changes: 27 additions & 0 deletions fixtures/compress/atrules/media-not-nested.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* issue #476: nested `not` in media conditions must not drop the @media rule */
@media (max-width: 701px) and (not (any-pointer: fine)) {
.a { color: red; }
}

@media (not (color)) {
.b { color: blue; }
}

@media (max-width: 701px) and (not (any-pointer: fine)), (hover: none) {
.c { color: green; }
}

@media not screen {
.d { color: black; }
}

@media (max-width: 701px) and (not (any-pointer: fine)) {
.x { color: red; }
}

@media (max-width: 701px) and (not (any-pointer: fine)) {
.y { color: blue; }
}

@media (max-width: 701px) and (not (any-pointer: fine)) {
}
1 change: 1 addition & 0 deletions fixtures/compress/atrules/media-not-nested.min.css

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

6 changes: 3 additions & 3 deletions lib/clean/Atrule.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { keyword as resolveKeyword } from 'css-tree';
import { hasNoChildren } from './utils.js';
import { hasNoChildren, isEmptyAtrulePrelude } from './utils.js';

export default function cleanAtrule(node, item, list) {
if (node.block) {
Expand All @@ -16,7 +16,7 @@ export default function cleanAtrule(node, item, list) {

switch (node.name) {
case 'charset':
if (hasNoChildren(node.prelude)) {
if (isEmptyAtrulePrelude(node.prelude)) {
list.remove(item);
return;
}
Expand Down Expand Up @@ -60,7 +60,7 @@ export default function cleanAtrule(node, item, list) {
name === 'supports') {

// drop at-rule with no prelude
if (hasNoChildren(node.prelude) || hasNoChildren(node.block)) {
if (isEmptyAtrulePrelude(node.prelude) || hasNoChildren(node.block)) {
list.remove(item);
}
}
Expand Down
15 changes: 15 additions & 0 deletions lib/clean/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ export function hasNoChildren(node) {
return !node || !node.children || node.children.isEmpty;
}

// css-tree emits a Raw node (no `children` list) when a prelude fails to parse,
// e.g. Media Queries Level 4 nested `not` conditions. A non-empty Raw value is
// still a real prelude and must not be treated as missing (issue #476).
export function isEmptyAtrulePrelude(node) {
if (!node) {
return true;
}

if (node.type === 'Raw') {
return !node.value;
}

return hasNoChildren(node);
}

export function isNodeChildrenList(node, list) {
return node !== null && node.children === list;
}