No description
This PR fixes a bug in the canonicalization process when we simplify / fold declarations that contain `0<unit>` values. The reason we even try to fold these in the first place is to simplify values such as `m-[0rem]` to `m-0`. The more values we can fold/canonicalize, the better we can suggest replacements _if_ they are the same. One thing we know in CSS is that if you have a `<length>` type, and that value is `0<unit>`, then we can safely change that to just `0`. ```css width: 0rem; width: 0; /* `0` is a <length> */ ``` However, if this was part of a `calc(…)` (or another CSS math function), then this could make the calc expression invalid: - `calc(1rem + 0px)` → `calc(1rem + 0)` — this goes from _valid_ to _invalid_ At runtime the `1rem` can be converted to a `px` based valued, then `16px + 0px` makes sense. Adding `0` without unit does not. - `calc(1rem * 0px)` → `calc(1rem * 0)` — this goes from _invalid_ to _valid_ At runtime the `1rem` can be converted to a `px` based value, but `16px * 0px` would result in `0px^2` which doesn't make sense either. We will still normalize values such as `-0.0rem` to just `0rem`, but not `0` if we know it's unsafe to do so. If we end up with top-level `calc(…)` expressions that can be folded, then we will try to do that: - `calc(0px * -1)` → `0` - `calc(calc(0px * -1) + 1rem)` → `calc(0px + 1rem)` Notice that the inner `calc(…)` was folded to `0px` not `0` because that would make the `calc(0 + 1rem)` invalid. Additionally, we could potentially fold the `calc(0px + 1rem)` to just `1rem`, but we have to make sure that we don't introduce valid values from invalid values `calc(0s + 1rem)` would be invalid, but folding it to `1rem` would make it valid which is not good. Fixes: https://github.com/tailwindlabs/tailwindcss-intellisense/issues/1579 |
||
|---|---|---|
| .github | ||
| crates | ||
| integrations | ||
| packages | ||
| patches | ||
| playgrounds | ||
| scripts | ||
| .gitignore | ||
| .prettierignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| CHANGELOG.md | ||
| LICENSE | ||
| package.json | ||
| pnpm-lock.yaml | ||
| pnpm-workspace.yaml | ||
| README.md | ||
| rust-toolchain.toml | ||
| turbo.json | ||
| vitest.config.ts | ||
A utility-first CSS framework for rapidly building custom user interfaces.
Documentation
For full documentation, visit tailwindcss.com.
Community
For help, discussion about best practices, or feature ideas:
Discuss Tailwind CSS on GitHub
Contributing
If you're interested in contributing to Tailwind CSS, please read our contributing docs before submitting a pull request.