parcel-bundler / lightningcss

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

Option to not add units of measure #682

Open stoyan opened 4 months ago

stoyan commented 4 months ago

Currently

a{width:1}

becomes

a{width:1px}

which breaks my UI by turning invalid CSS into a valid one.

(Of course the right thing to do is to fix my origin code to not contain invalid CSS. But in a large project that may take a while and hurt the adoption of LightningCSS.)

I think in this case the correct behavior would be to drop the property completely as its value is incorrect.

devongovett commented 2 months ago

Lightning CSS is a bit lenient here to support quirks mode, where unitless lengths are supported in some properties: https://drafts.csswg.org/css-values-4/#deprecated-quirky-length. Perhaps there should be an option to make this more strict, as mentioned in the code here: https://github.com/parcel-bundler/lightningcss/blob/445def9a77f89aa612fecb2f776261fc2c9d8f66/src/values/length.rs#L145-L148