Commit d698c10
authored
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.
1 parent cec7f05 commit d698c10
File tree
6 files changed
+37
-1
lines changed- packages/tailwindcss/src
- compat
6 files changed
+37
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
152 | 153 | | |
153 | 154 | | |
154 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17961 | 17961 | | |
17962 | 17962 | | |
17963 | 17963 | | |
| 17964 | + | |
| 17965 | + | |
| 17966 | + | |
| 17967 | + | |
| 17968 | + | |
| 17969 | + | |
| 17970 | + | |
| 17971 | + | |
| 17972 | + | |
| 17973 | + | |
| 17974 | + | |
| 17975 | + | |
| 17976 | + | |
| 17977 | + | |
| 17978 | + | |
| 17979 | + | |
| 17980 | + | |
| 17981 | + | |
| 17982 | + | |
| 17983 | + | |
| 17984 | + | |
| 17985 | + | |
| 17986 | + | |
| 17987 | + | |
| 17988 | + | |
| 17989 | + | |
| 17990 | + | |
| 17991 | + | |
| 17992 | + | |
| 17993 | + | |
| 17994 | + | |
| 17995 | + | |
17964 | 17996 | | |
17965 | 17997 | | |
17966 | 17998 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4885 | 4885 | | |
4886 | 4886 | | |
4887 | 4887 | | |
4888 | | - | |
| 4888 | + | |
4889 | 4889 | | |
4890 | 4890 | | |
4891 | 4891 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
0 commit comments