tailwindcss/packages
Robin Malfait 01d1e98259
Canonicalization constant folding and handling zeros (#19095)
The main goal of this PR was to support canonicalization of zero like
values. We essentially want to canonicalize `-mt-0` as `mt-0`, but also
`mt-[0px]`, `mt-[0rem]`, and other length-like units to just `mt-0`.

To do this, we had to handle 2 things:

1. We introduced some more constant folding, including making `0px` and
`0rem` fold to `0`. We only do this for length units. We also normalize
`-0`, `+0`, `-0.0` and so on to `0`.
2. While pre-computing utilities in our lookup table, we make sure that
we prefer `mt-0` over `-mt-0` if both result in the same signature.

Moved some of the constant folding logic into its own function and added
a bunch of separate tests for it.

## Test plan

Added more unit tests where we normalize different zero-like values to
`0`.

Running the canonicalization logic:
```js
designSystem.canonicalizeCandidates([
  '-m-0',
  '-m-[-0px]',
  '-m-[-0rem]',
  '-m-[0px]',
  '-m-[0rem]',
  'm-0',
  'm-[-0px]',
  'm-[-0rem]',
  'm-[0px]',
  'm-[0rem]',
  'm-[calc(var(--spacing)*0)]',
  'm-[--spacing(0)]',
  'm-[--spacing(0.0)]',
  'm-[+0]',
  'm-[-0]',
  '-m-[-0]',
  '-m-[+0]',
]) // → ['m-0']
```

---------

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2025-10-09 18:09:29 +00:00
..
@tailwindcss-browser Introduce canonicalizeCandidates on the internal Design System (#19059) 2025-10-07 12:41:12 +02:00
@tailwindcss-cli Prepare v4.1.14 release (#19037) 2025-10-01 11:48:02 -04:00
@tailwindcss-node Suppress warnings when using :deep, :slotted and :global (#19094) 2025-10-09 11:58:51 +02:00
@tailwindcss-postcss Prepare v4.1.14 release (#19037) 2025-10-01 11:48:02 -04:00
@tailwindcss-standalone Prepare v4.1.14 release (#19037) 2025-10-01 11:48:02 -04:00
@tailwindcss-upgrade Canonicalization constant folding and handling zeros (#19095) 2025-10-09 18:09:29 +00:00
@tailwindcss-vite Prepare v4.1.14 release (#19037) 2025-10-01 11:48:02 -04:00
internal-example-plugin Prefix internal modules with internal-* (#14074) 2024-07-29 10:58:07 -04:00
tailwindcss Canonicalization constant folding and handling zeros (#19095) 2025-10-09 18:09:29 +00:00
tsconfig.base.json Improve debug logs (#15303) 2024-12-11 15:27:20 +01:00