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

Do not create duplicate rules for duplicate media queries #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions lib/css_parser/parser.rb
Expand Up @@ -258,6 +258,7 @@ def to_s(which_media = :all)
each_selector(which_media) do |selectors, declarations, specificity, media_types|
media_types.each do |media_type|
styles_by_media_types[media_type] ||= []
next if styles_by_media_types[media_type].include?([selectors, declarations])
styles_by_media_types[media_type] << [selectors, declarations]
end
end
Expand Down
19 changes: 19 additions & 0 deletions test/test_css_parser_media_types.rb
Expand Up @@ -8,6 +8,25 @@ def setup
@cp = Parser.new
end

def test_that_duplicate_media_queries_do_not_duplicate_rules
query_to_duplicate = ["only screen and (max-width: 480px)"]*100
@cp.add_block!(<<-CSS)
@media only screen and (max-width: 480px), #{query_to_duplicate.join(', ')} {
body { color: red; }
}
CSS

expected = <<-CSS
@media only screen and (max-width: 480px) {
body {
color: red;
}
}
CSS

assert_equal expected, @cp.to_s
end

def test_that_media_types_dont_include_all
@cp.add_block!(<<-CSS)
@media handheld {
Expand Down