tailwindcss/packages
Robin Malfait d698c10836
Ensure multiple --value(…) or --modifier(…) calls don't delete subsequent declarations (#17273)
This PR fixes a bug in the handling of `@utility`. Essentially if you
had a declaration where you used a `--modifier(…)` _and_ a `--value(…)`
and both caused the declaration to be removed, the declaration after the
current one would be removed as well.

This happened because 2 reasons:

1. Once we removed the declaration when we handled `--modifier(…)`, we
didn't stop the walk and kept going.
2. The `replaceWith(…)` code allows you to call the function multiple
times but immediately mutates the AST. This means that if you call it
multiple times that you are potentially removing / updating nodes
followed by the current one.

E.g.:

```css
@utility mask-r-* {
  --mask-right: linear-gradient(to left, transparent, black --value(percentage));
  --mask-right: linear-gradient(
    to left,
    transparent calc(var(--spacing) * --modifier(integer)),
    black calc(var(--spacing) * --value(integer))
  );
  mask-image: var(--mask-linear), var(--mask-radial), var(--mask-conic);
}
```

If this is used as `mask-r-10%`, then the first definition of
`--mask-right` is kept, but the second definition of `--mask-right` is
deleted because both `--modifier(integer)` and `--value(integer)` do not
result in a valid value.

However, the `mask-image` declaration was also removed because the
`replaceWith(…)` function was called twice. Once for
`--modifier(integer)` and once for `--value(integer)`.

# Test plan

1. Added a test to cover this case.
2. Existing tests pass.
3. Added a hard error if we call `replaceWith(…)` multiple times.
2025-03-19 13:25:53 +00:00
..
@tailwindcss-browser Prepare v4.0.14 release (#17173) 2025-03-13 12:36:34 +01:00
@tailwindcss-cli Prepare v4.0.14 release (#17173) 2025-03-13 12:36:34 +01:00
@tailwindcss-node Prepare v4.0.14 release (#17173) 2025-03-13 12:36:34 +01:00
@tailwindcss-postcss Remove redundant line-height from body (#15212) 2025-03-18 12:23:49 +01:00
@tailwindcss-standalone Prepare v4.0.14 release (#17173) 2025-03-13 12:36:34 +01:00
@tailwindcss-upgrade Prepare v4.0.14 release (#17173) 2025-03-13 12:36:34 +01:00
@tailwindcss-vite Prepare v4.0.14 release (#17173) 2025-03-13 12:36:34 +01:00
internal-example-plugin Prefix internal modules with internal-* (#14074) 2024-07-29 10:58:07 -04:00
tailwindcss Ensure multiple --value(…) or --modifier(…) calls don't delete subsequent declarations (#17273) 2025-03-19 13:25:53 +00:00
tsconfig.base.json Improve debug logs (#15303) 2024-12-11 15:27:20 +01:00