Repository navigation
🐛 fix(css): keep at-statements browsers ignore dead in minify_css - #2145
Conversation
The CSS minifier could turn an @import, @namespace, @charset or @layer statement that a browser ignores in the source into a live one. A top-level at-statement prelude ended at a stray `}`, so the minifier split a dropped at-rule into a statement of its own. An empty rule or empty conditional group rule was removed even when it was what kept a following @import or @namespace out of place. A top-level `<!--` or `-->` was kept as stray text, and some selector or escape spellings wrote one the source did not have. The top-level prelude now reads through `}` to a `;` or a block, as CSS Syntax 3 parses it. Empty top-level rules are held and written back in front of the next @import, @namespace or @charset. The top level skips `<!--` and `-->` like a browser, and the selector and name writers no longer spell one where the source had none. Fixes tox-dev#1745.
Merging this PR will improve performance by 8.43%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
minify_css()could turn an at-statement that browsers ignore into one they honor. 🎨 An@import,@namespace,@charsetor@layerstatement sits behind rules that make it dead in the source. Minifying removed an empty rule in front of it, and a stray}split a statement that browsers drop whole, so the remainder became a statement of its own. A minified sheet could then load a stylesheet or apply a namespace the original did not. After this change the minified sheet keeps every such statement dead, as the source has it.A browser honors
@importonly ahead of every rule other than@charsetand@layerstatements (CSS Cascade 5), and@namespaceonly ahead of every rule other than those and@import(CSS Namespaces 3). An empty rule has no effect on matching, but it still counts as a rule. The minifier holds such rules back and writes them in front of the next statement whose order they affect. Top-level<!--and-->tokens are skipped as in consume a list of rules. Selector minification keeps a separator where removing it would spell a<!--or-->token.Behavior changes
<!--and-->before rules and at-rules are dropped from the output.@media,@supportsor@container, before an@import,@namespaceor@charsetat the top level is kept. The rule moves to just before that statement, so it can come after an@layerstatement that followed it in the source. An empty@mediais written as*{}, so such output is a few bytes longer.}is kept through to its;or block.--name and>, and between<!and a--name. Selector lists with such an arm are not merged.Fixes #1745.