Skip to content

Commit

Permalink
fix : postcss#512
Browse files Browse the repository at this point in the history
  • Loading branch information
romainmenke committed Dec 1, 2022
1 parent 13376a6 commit c840238
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion lib/join-media.js
@@ -1,5 +1,7 @@
"use strict"

const startsWithKeywordRegexp = /^(all|not|screen|print)/i

module.exports = function (parentMedia, childMedia) {
if (!parentMedia.length && childMedia.length) return childMedia
if (parentMedia.length && !childMedia.length) return parentMedia
Expand All @@ -8,8 +10,17 @@ module.exports = function (parentMedia, childMedia) {
const media = []

parentMedia.forEach(parentItem => {
const parentItemStartsWithKeyword = startsWithKeywordRegexp.test(parentItem)

childMedia.forEach(childItem => {
if (parentItem !== childItem) media.push(`${parentItem} and ${childItem}`)
const childItemStartsWithKeyword = startsWithKeywordRegexp.test(childItem)
if (parentItem !== childItem) {
if (childItemStartsWithKeyword && !parentItemStartsWithKeyword) {
media.push(`${childItem} and ${parentItem}`)
} else {
media.push(`${parentItem} and ${childItem}`)
}
}
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/filter-ignore.expected.css
@@ -1,5 +1,5 @@
@import "http://css" (min-width: 25em);
@import "http://css-screen" (min-width: 25em) and screen;
@import "http://css-screen" screen and (min-width: 25em);
@import "http://css";
@import "https://css";
@import 'http://css';
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/ignore.expected.css
@@ -1,5 +1,5 @@
@import "http://css" (min-width: 25em);
@import "http://css-screen" (min-width: 25em) and screen;
@import "http://css-screen" screen and (min-width: 25em);
@import "http://css";
@import "https://css";
@import 'http://css';
Expand Down

0 comments on commit c840238

Please sign in to comment.