Skip to content

Commit 40bda05

Browse files
committed
move parts of migrate-modernize-arbitrary-values to core
The part where we upgrade old v3 syntax like `group-[]:` still exists in the `@tailwindcss/upgrade` package. We were relying on `postcss-selector-parser`, but the copied part is now using our own `SelectorParser`. I also added a temporary attribute selector parser to make everything pass. Don't look at the code for that _too_ much because we will swap it out in a later commit 😅
1 parent c6a3a4d commit 40bda05

File tree

4 files changed

+613
-415
lines changed

4 files changed

+613
-415
lines changed

packages/@tailwindcss-upgrade/src/codemods/template/migrate-modernize-arbitrary-values.test.ts

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,6 @@ function migrate(designSystem: DesignSystem, userConfig: UserConfig | null, rawC
2222
}
2323

2424
test.each([
25-
// Arbitrary variants
26-
['[[data-visible]]:flex', 'data-visible:flex'],
27-
['[&[data-visible]]:flex', 'data-visible:flex'],
28-
['[[data-visible]&]:flex', 'data-visible:flex'],
29-
['[&>[data-visible]]:flex', '*:data-visible:flex'],
30-
['[&_>_[data-visible]]:flex', '*:data-visible:flex'],
31-
['[&>*]:flex', '*:flex'],
32-
['[&_>_*]:flex', '*:flex'],
33-
34-
['[&_[data-visible]]:flex', '**:data-visible:flex'],
35-
['[&_*]:flex', '**:flex'],
36-
37-
['[&:first-child]:flex', 'first:flex'],
38-
['[&:not(:first-child)]:flex', 'not-first:flex'],
39-
40-
// in-* variants
41-
['[p_&]:flex', 'in-[p]:flex'],
42-
['[.foo_&]:flex', 'in-[.foo]:flex'],
43-
['[[data-visible]_&]:flex', 'in-data-visible:flex'],
44-
// Multiple selectors, should stay as-is
45-
['[[data-foo][data-bar]_&]:flex', '[[data-foo][data-bar]_&]:flex'],
46-
// Using `>` instead of ` ` should not be transformed:
47-
['[figure>&]:my-0', '[figure>&]:my-0'],
4825
// Some extreme examples of what happens in the wild:
4926
['group-[]:flex', 'in-[.group]:flex'],
5027
['group-[]/name:flex', 'in-[.group\\/name]:flex'],
@@ -59,71 +36,6 @@ test.each([
5936
['has-group-[]/name:flex', 'has-in-[.group\\/name]:flex'],
6037
['not-group-[]:flex', 'not-in-[.group]:flex'],
6138
['not-group-[]/name:flex', 'not-in-[.group\\/name]:flex'],
62-
63-
// nth-child
64-
['[&:nth-child(2)]:flex', 'nth-2:flex'],
65-
['[&:not(:nth-child(2))]:flex', 'not-nth-2:flex'],
66-
67-
['[&:nth-child(-n+3)]:flex', 'nth-[-n+3]:flex'],
68-
['[&:not(:nth-child(-n+3))]:flex', 'not-nth-[-n+3]:flex'],
69-
['[&:nth-child(-n_+_3)]:flex', 'nth-[-n+3]:flex'],
70-
['[&:not(:nth-child(-n_+_3))]:flex', 'not-nth-[-n+3]:flex'],
71-
72-
// nth-last-child
73-
['[&:nth-last-child(2)]:flex', 'nth-last-2:flex'],
74-
['[&:not(:nth-last-child(2))]:flex', 'not-nth-last-2:flex'],
75-
76-
['[&:nth-last-child(-n+3)]:flex', 'nth-last-[-n+3]:flex'],
77-
['[&:not(:nth-last-child(-n+3))]:flex', 'not-nth-last-[-n+3]:flex'],
78-
['[&:nth-last-child(-n_+_3)]:flex', 'nth-last-[-n+3]:flex'],
79-
['[&:not(:nth-last-child(-n_+_3))]:flex', 'not-nth-last-[-n+3]:flex'],
80-
81-
// nth-child odd/even
82-
['[&:nth-child(odd)]:flex', 'odd:flex'],
83-
['[&:not(:nth-child(odd))]:flex', 'even:flex'],
84-
['[&:nth-child(even)]:flex', 'even:flex'],
85-
['[&:not(:nth-child(even))]:flex', 'odd:flex'],
86-
87-
// Keep multiple attribute selectors as-is
88-
['[[data-visible][data-dark]]:flex', '[[data-visible][data-dark]]:flex'],
89-
90-
// Keep `:where(…)` as is
91-
['[:where([data-visible])]:flex', '[:where([data-visible])]:flex'],
92-
93-
// Complex attribute selectors with operators, quotes and insensitivity flags
94-
['[[data-url*="example"]]:flex', 'data-[url*="example"]:flex'],
95-
['[[data-url$=".com"_i]]:flex', 'data-[url$=".com"_i]:flex'],
96-
['[[data-url$=.com_i]]:flex', 'data-[url$=.com_i]:flex'],
97-
98-
// Attribute selector wrapped in `&:is(…)`
99-
['[&:is([data-visible])]:flex', 'data-visible:flex'],
100-
101-
// Media queries
102-
['[@media(pointer:fine)]:flex', 'pointer-fine:flex'],
103-
['[@media_(pointer_:_fine)]:flex', 'pointer-fine:flex'],
104-
['[@media_not_(pointer_:_fine)]:flex', 'not-pointer-fine:flex'],
105-
['[@media_print]:flex', 'print:flex'],
106-
['[@media_not_print]:flex', 'not-print:flex'],
107-
108-
// Hoist the `:not` part to a compound variant
109-
['[@media_not_(prefers-color-scheme:dark)]:flex', 'not-dark:flex'],
110-
[
111-
'[@media_not_(prefers-color-scheme:unknown)]:flex',
112-
'not-[@media_(prefers-color-scheme:unknown)]:flex',
113-
],
114-
115-
// Compound arbitrary variants
116-
['has-[[data-visible]]:flex', 'has-data-visible:flex'],
117-
['has-[&:is([data-visible])]:flex', 'has-data-visible:flex'],
118-
['has-[&>[data-visible]]:flex', 'has-[&>[data-visible]]:flex'],
119-
120-
['has-[[data-slot=description]]:flex', 'has-data-[slot=description]:flex'],
121-
['has-[&:is([data-slot=description])]:flex', 'has-data-[slot=description]:flex'],
122-
123-
['has-[[aria-visible="true"]]:flex', 'has-aria-visible:flex'],
124-
['has-[[aria-visible]]:flex', 'has-aria-[visible]:flex'],
125-
126-
['has-[&:not(:nth-child(even))]:flex', 'has-odd:flex'],
12739
])('%s => %s (%#)', async (candidate, result) => {
12840
let designSystem = await __unstable__loadDesignSystem('@import "tailwindcss";', {
12941
base: __dirname,

0 commit comments

Comments
 (0)