@@ -14,7 +14,7 @@ test.each([
14
14
[ '[--value:theme(spacing[1.25])]' , '[--value:--spacing(1.25)]' ] ,
15
15
16
16
// Should not convert invalid spacing values to calc
17
- [ '[--value:theme(spacing[1.1])]' , '[--value:theme(spacing[1.1])]' ] ,
17
+ [ '[--value:theme(spacing[1.1])]' , '[--value:-- theme(spacing[1.1])]' ] ,
18
18
19
19
// Convert to `var(…)` if we can resolve the path
20
20
[ '[color:theme(colors.red.500)]' , '[color:var(--color-red-500)]' ] , // Arbitrary property
@@ -26,13 +26,13 @@ test.each([
26
26
[ 'bg-[theme(colors.red.500,red)]' , 'bg-(--color-red-500,red)' ] ,
27
27
28
28
// Keep `theme(…)` if we can't resolve the path
29
- [ 'bg-[theme(colors.foo.1000)]' , 'bg-[theme(colors.foo.1000)]' ] ,
29
+ [ 'bg-[theme(colors.foo.1000)]' , 'bg-[-- theme(colors.foo.1000)]' ] ,
30
30
31
31
// Keep `theme(…)` if we can't resolve the path, but still try to convert the
32
32
// fallback value.
33
33
[
34
34
'bg-[theme(colors.foo.1000,theme(colors.red.500))]' ,
35
- 'bg-[theme(colors.foo.1000,var(--color-red-500))]' ,
35
+ 'bg-[-- theme(colors.foo.1000,var(--color-red-500))]' ,
36
36
] ,
37
37
38
38
// Use `theme(…)` (deeply nested) inside of a `calc(…)` function
@@ -47,11 +47,11 @@ test.each([
47
47
// to a candidate modifier _if_ all `theme(…)` calls use the same modifier.
48
48
[
49
49
'[color:theme(colors.red.500/50,theme(colors.blue.500/50))]' ,
50
- '[color:theme(--color-red-500/50,theme(--color-blue-500/50))]' ,
50
+ '[color:-- theme(--color-red-500/50,-- theme(--color-blue-500/50))]' ,
51
51
] ,
52
52
[
53
53
'[color:theme(colors.red.500/50,theme(colors.blue.500/50))]/50' ,
54
- '[color:theme(--color-red-500/50,theme(--color-blue-500/50))]/50' ,
54
+ '[color:-- theme(--color-red-500/50,-- theme(--color-blue-500/50))]/50' ,
55
55
] ,
56
56
57
57
// Convert the `theme(…)`, but try to move the inline modifier (e.g. `50%`),
@@ -75,52 +75,52 @@ test.each([
75
75
[ 'bg-[theme(colors.red.500/12.34%)]' , 'bg-(--color-red-500)/[12.34%]' ] ,
76
76
77
77
// Arbitrary property that already contains a modifier
78
- [ '[color:theme(colors.red.500/50%)]/50' , '[color:theme(--color-red-500/50%)]/50' ] ,
78
+ [ '[color:theme(colors.red.500/50%)]/50' , '[color:-- theme(--color-red-500/50%)]/50' ] ,
79
79
80
80
// Values that don't contain only `theme(…)` calls should not be converted to
81
81
// use a modifier since the color is not the whole value.
82
82
[
83
83
'shadow-[shadow:inset_0px_1px_theme(colors.white/15%)]' ,
84
- 'shadow-[shadow:inset_0px_1px_theme (--color-white/15%)]' ,
84
+ 'shadow-[shadow:inset_0px_1px_--theme (--color-white/15%)]' ,
85
85
] ,
86
86
87
87
// Arbitrary value, where the candidate already contains a modifier
88
88
// This should still migrate the `theme(…)` syntax to the modern syntax.
89
- [ 'bg-[theme(colors.red.500/50%)]/50' , 'bg-[theme(--color-red-500/50%)]/50' ] ,
89
+ [ 'bg-[theme(colors.red.500/50%)]/50' , 'bg-[-- theme(--color-red-500/50%)]/50' ] ,
90
90
91
91
// Variants, we can't use `var(…)` especially inside of `@media(…)`. We can
92
92
// still upgrade the `theme(…)` to the modern syntax.
93
- [ 'max-[theme(screens.lg)]:flex' , 'max-[theme(--breakpoint-lg)]:flex' ] ,
93
+ [ 'max-[theme(screens.lg)]:flex' , 'max-[-- theme(--breakpoint-lg)]:flex' ] ,
94
94
// There are no variables for `--spacing` multiples, so we can't convert this
95
- [ 'max-[theme(spacing.4)]:flex' , 'max-[theme(spacing.4)]:flex' ] ,
95
+ [ 'max-[theme(spacing.4)]:flex' , 'max-[-- theme(spacing.4)]:flex' ] ,
96
96
97
97
// This test in itself doesn't make much sense. But we need to make sure
98
98
// that this doesn't end up as the modifier in the candidate itself.
99
- [ 'max-[theme(spacing.4/50)]:flex' , 'max-[theme(spacing.4/50)]:flex' ] ,
99
+ [ 'max-[theme(spacing.4/50)]:flex' , 'max-[-- theme(spacing.4/50)]:flex' ] ,
100
100
101
101
// `theme(…)` calls in another CSS function is replaced correctly.
102
102
// Additionally we remove unnecessary whitespace.
103
103
[ 'grid-cols-[min(50%_,_theme(spacing.80))_auto]' , 'grid-cols-[min(50%,--spacing(80))_auto]' ] ,
104
104
105
105
// `theme(…)` calls valid in v3, but not in v4 should still be converted.
106
- [ '[--foo:theme(transitionDuration.500)]' , '[--foo:theme(transitionDuration.500)]' ] ,
106
+ [ '[--foo:theme(transitionDuration.500)]' , '[--foo:-- theme(transitionDuration.500)]' ] ,
107
107
108
108
// Renamed theme keys
109
109
[ 'max-w-[theme(screens.md)]' , 'max-w-(--breakpoint-md)' ] ,
110
110
[ 'w-[theme(maxWidth.md)]' , 'w-(--container-md)' ] ,
111
111
112
112
// Invalid cases
113
- [ '[--foo:theme(colors.red.500/50/50)]' , '[--foo:theme(colors.red.500/50/50)]' ] ,
114
- [ '[--foo:theme(colors.red.500/50/50)]/50' , '[--foo:theme(colors.red.500/50/50)]/50' ] ,
113
+ [ '[--foo:theme(colors.red.500/50/50)]' , '[--foo:-- theme(colors.red.500/50/50)]' ] ,
114
+ [ '[--foo:theme(colors.red.500/50/50)]/50' , '[--foo:-- theme(colors.red.500/50/50)]/50' ] ,
115
115
116
116
// Partially invalid cases
117
117
[
118
118
'[--foo:theme(colors.red.500/50/50)_theme(colors.blue.200)]' ,
119
- '[--foo:theme(colors.red.500/50/50)_var(--color-blue-200)]' ,
119
+ '[--foo:-- theme(colors.red.500/50/50)_var(--color-blue-200)]' ,
120
120
] ,
121
121
[
122
122
'[--foo:theme(colors.red.500/50/50)_theme(colors.blue.200)]/50' ,
123
- '[--foo:theme(colors.red.500/50/50)_var(--color-blue-200)]/50' ,
123
+ '[--foo:-- theme(colors.red.500/50/50)_var(--color-blue-200)]/50' ,
124
124
] ,
125
125
] ) ( '%s => %s' , async ( candidate , result ) => {
126
126
let designSystem = await __unstable__loadDesignSystem (
@@ -158,7 +158,7 @@ test('extended space scale converts to var or calc', async () => {
158
158
'[--value:var(--spacing-miami)]' ,
159
159
)
160
160
expect ( themeToVar ( designSystem , { } , '[--value:theme(spacing.nyc)]' ) ) . toEqual (
161
- '[--value:theme(spacing.nyc)]' ,
161
+ '[--value:-- theme(spacing.nyc)]' ,
162
162
)
163
163
} )
164
164
@@ -183,6 +183,6 @@ test('custom space scale converts to var', async () => {
183
183
'[--value:var(--spacing-2)]' ,
184
184
)
185
185
expect ( themeToVar ( designSystem , { } , '[--value:theme(spacing.3)]' ) ) . toEqual (
186
- '[--value:theme(spacing.3)]' ,
186
+ '[--value:-- theme(spacing.3)]' ,
187
187
)
188
188
} )
0 commit comments