css-minify icon indicating copy to clipboard operation
css-minify copied to clipboard

Storing declarations as a map results in a "dangerous" optimization in level 0

Open andreubotella opened this issue 2 years ago • 0 comments

Take the following CSS code:

.test::after {
  content: url("./image.jpg");
  content: url("./image.jpg") / "Some alt text";
}

The second declaration in the block is a valid value for the content CSS property, at least according to the CSS Content Level 3 specification (see here in MDN), but it is only supported in Chromium browsers, and not in Firefox or Safari.

Declaring the content property twice in the same block achieves backwards compatibility for browsers that don't support the newer syntax for that property, since a declaration which doesn't have correct syntax for the given property will be ignored. Therefore, Firefox and Safari will use url("./image.png") as the value of the content property, and Chromium browsers will use url("./image.png") / "Some alt text".

css-minify, however, stores the CSS declarations in a block as a map from CSS properties to a single value, which means only the latter value is stored in the map. Therefore, even with level 0, the result of minification is:

.test:after {content:url("./image.jpg") / "Some alt text"}

which behaves differently from the original CSS.

andreubotella avatar Feb 26 '23 18:02 andreubotella