parcel-bundler / lightningcss

An extremely fast CSS parser, transformer, bundler, and minifier written in Rust.
https://lightningcss.dev
Mozilla Public License 2.0
6.56k stars 190 forks source link

Declaration blocks for unrecognized pseudo-elements are not merged #774

Closed birtles closed 4 months ago

birtles commented 4 months ago

Playground link

Input:

::-webkit-inner-spin-button {
  height: auto;
}
::-webkit-outer-spin-button {
  height: auto;
}

Expected:

::-webkit-inner-spin-button, ::-webkit-outer-spin-button {
  height: auto;
}

Actual:

::-webkit-inner-spin-button {
  height: auto;
}

::-webkit-outer-spin-button {
  height: auto;
}

I only came across this because it looks like rspack's SwcCssMinimizerRspackPlugin does this while the Lightning plugin does not.

I guess it's safe to merge declaration blocks whose selectors include unrecognized pseudo-elements but maybe it's not common enough to worry about? Just filing this for completeness. Feel free to close it.

devongovett commented 4 months ago

It is not safe. Say a browser supports one of these selectors but not the other. If they are merged, the whole rule is thrown away by the browser rather than applying the supported selector. Lightning CSS has knowledge of the supported selectors of each browser and tries to merge if possible, but if it doesn't know about a selector it is conservative and keeps them separate to be on the safe side.

birtles commented 4 months ago

Right you are. I hadn't thought about that. Thank you!