Commit 3dc3bad
Re-introduce automatic var injection shorthand (#15020)
This PR re-introduces the automatic var injection feature.
For some backstory, we used to support classes such as `bg-[--my-color]`
that resolved as-if you wrote `bg-[var(--my-color)]`.
The is issue is that some newer CSS properties accepts dashed-idents
(without the `var(…)`). This means that some properties accept
`view-timeline-name: --my-name;` (see:
https://developer.mozilla.org/en-US/docs/Web/CSS/view-timeline-name).
To make this a tiny bit worse, these properties _also_ accept
`var(--my-name-reference)` where the variable `--my-name-reference`
could reference a dashed-ident such as `--my-name`.
This makes the `bg-[--my-color]` ambiguous because we don't know if you
want `var(--my-color)` or `--my-color`.
With this PR, we bring back the automatic var injection feature as
syntactic sugar, but we use a different syntax to avoid the ambiguity.
Instead of `bg-[--my-color]`, you can now write `bg-(--my-color)` to get
the same effect as `bg-[var(--my-color)]`.
This also applies to modifiers, so `bg-red-500/[var(--my-opacity)]` can
be written as `bg-red-500/(--my-opacity)`. To go full circle, you can
rewrite `bg-[var(--my-color)]/[var(--my-opacity)]` as
`bg-(--my-color)/(--my-opacity)`.
---
This is implemented as syntactical sugar at the parsing stage and
handled when re-printing. Internally the system (and every plugin) still
see the proper `var(--my-color)` value.
Since this is also handled during printing of the candidate, codemods
don't need to be changed but they will provide the newly updated syntax.
E.g.: running this on the Catalyst codebase, you'll now see changes like
this:
<img width="542" alt="image"
src="https://github.com/user-attachments/assets/8f0e26f8-f4c9-4cdc-9f28-52307c38610e">
Whereas before we converted this to the much longer
`min-w-[var(--button-width)]`.
---
Additionally, this required some changes to the Oxide scanner to make
sure that `(` and `)` are valid characters for arbitrary-like values.
---------
Co-authored-by: Adam Wathan <adam.wathan@gmail.com>1 parent 9c3bfd6 commit 3dc3bad
File tree
11 files changed
+352
-76
lines changed- crates/oxide/src
- integrations/upgrade
- packages
- @tailwindcss-upgrade/src/template
- codemods
- tailwindcss/src
11 files changed
+352
-76
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
42 | 60 | | |
43 | 61 | | |
44 | 62 | | |
| |||
48 | 66 | | |
49 | 67 | | |
50 | 68 | | |
51 | | - | |
52 | 69 | | |
53 | | - | |
| 70 | + | |
| 71 | + | |
54 | 72 | | |
55 | 73 | | |
56 | 74 | | |
| |||
105 | 123 | | |
106 | 124 | | |
107 | 125 | | |
108 | | - | |
109 | 126 | | |
110 | | - | |
| 127 | + | |
111 | 128 | | |
112 | 129 | | |
113 | 130 | | |
| |||
461 | 478 | | |
462 | 479 | | |
463 | 480 | | |
464 | | - | |
| 481 | + | |
465 | 482 | | |
466 | 483 | | |
467 | 484 | | |
| |||
479 | 496 | | |
480 | 497 | | |
481 | 498 | | |
482 | | - | |
483 | | - | |
484 | | - | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
485 | 522 | | |
486 | 523 | | |
487 | 524 | | |
| |||
501 | 538 | | |
502 | 539 | | |
503 | 540 | | |
504 | | - | |
505 | | - | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
506 | 544 | | |
507 | | - | |
508 | | - | |
509 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
510 | 549 | | |
511 | 550 | | |
512 | 551 | | |
| |||
531 | 570 | | |
532 | 571 | | |
533 | 572 | | |
534 | | - | |
535 | | - | |
536 | | - | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
537 | 580 | | |
538 | 581 | | |
539 | 582 | | |
| |||
550 | 593 | | |
551 | 594 | | |
552 | 595 | | |
553 | | - | |
| 596 | + | |
554 | 597 | | |
555 | 598 | | |
556 | | - | |
557 | | - | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
558 | 602 | | |
559 | 603 | | |
560 | 604 | | |
| |||
584 | 628 | | |
585 | 629 | | |
586 | 630 | | |
587 | | - | |
| 631 | + | |
| 632 | + | |
588 | 633 | | |
589 | 634 | | |
590 | 635 | | |
591 | 636 | | |
592 | 637 | | |
593 | 638 | | |
594 | | - | |
595 | | - | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
596 | 642 | | |
597 | 643 | | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
602 | 652 | | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
603 | 656 | | |
604 | 657 | | |
605 | 658 | | |
| |||
684 | 737 | | |
685 | 738 | | |
686 | 739 | | |
687 | | - | |
| 740 | + | |
688 | 741 | | |
689 | 742 | | |
690 | 743 | | |
| |||
696 | 749 | | |
697 | 750 | | |
698 | 751 | | |
699 | | - | |
| 752 | + | |
700 | 753 | | |
701 | 754 | | |
702 | 755 | | |
703 | 756 | | |
704 | 757 | | |
705 | | - | |
| 758 | + | |
706 | 759 | | |
707 | 760 | | |
708 | 761 | | |
| |||
732 | 785 | | |
733 | 786 | | |
734 | 787 | | |
735 | | - | |
736 | 788 | | |
737 | | - | |
| 789 | + | |
738 | 790 | | |
739 | 791 | | |
740 | 792 | | |
| |||
977 | 1029 | | |
978 | 1030 | | |
979 | 1031 | | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
980 | 1044 | | |
981 | 1045 | | |
982 | 1046 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
155 | | - | |
156 | | - | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| |||
639 | 639 | | |
640 | 640 | | |
641 | 641 | | |
642 | | - | |
| 642 | + | |
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
| |||
798 | 798 | | |
799 | 799 | | |
800 | 800 | | |
801 | | - | |
| 801 | + | |
802 | 802 | | |
803 | 803 | | |
804 | 804 | | |
| |||
873 | 873 | | |
874 | 874 | | |
875 | 875 | | |
876 | | - | |
| 876 | + | |
877 | 877 | | |
878 | 878 | | |
879 | 879 | | |
| |||
1447 | 1447 | | |
1448 | 1448 | | |
1449 | 1449 | | |
1450 | | - | |
| 1450 | + | |
1451 | 1451 | | |
1452 | 1452 | | |
1453 | 1453 | | |
| |||
1664 | 1664 | | |
1665 | 1665 | | |
1666 | 1666 | | |
1667 | | - | |
| 1667 | + | |
1668 | 1668 | | |
1669 | 1669 | | |
1670 | 1670 | | |
| |||
1799 | 1799 | | |
1800 | 1800 | | |
1801 | 1801 | | |
1802 | | - | |
| 1802 | + | |
1803 | 1803 | | |
1804 | 1804 | | |
1805 | 1805 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| |||
0 commit comments