mattbasta / crass

A CSS minifier and utility library for JavaScript
http://mattbasta.com/crass
MIT License
102 stars 6 forks source link

Incorrect handling of !important in optimization with duplicate elements #69

Closed scottadmi closed 6 years ago

scottadmi commented 6 years ago

Crass currently seems to ignore !important in prioritization when optimizing css elements.

In the following source: a { left: 0 !important; } div { color: red; } a { left: 1px; }

Crass produces: div { color: red; } a { left: 1px; }

The expected result is: div { color: red; } a { left: 0 !important; }

Interestingly if the div tag is removed from in between the two a tags, the result is correct.

mattbasta commented 6 years ago

Just pushed 0.12.3. Your expected result isn't something Crass can currently do. Crass tries to remove declarations in future rulesets that are overridden. Now it'll only try to remove them if they match !important flags, which means that the original CSS will remain unchanged.