Skip to content

Commit 87ecb18

Browse files
committed
Don’t allow not to be used with variants that have siblings
1 parent 6933fa6 commit 87ecb18

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

packages/tailwindcss/src/compile.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ export function applyVariant(
219219
let result = applyVariant(isolatedNode, variant.variant, variants, depth + 1)
220220
if (result === null) return null
221221

222+
if (variant.root === 'not' && isolatedNode.nodes.length > 1) {
223+
// The `not` variant cannot negate sibling rules / at-rules because these
224+
// are an OR relationship. Doing so would require transforming sibling
225+
// nodes into nesting while negating them. This isn't possible with the
226+
// current implementation of the `not` variant or with how variants are
227+
// applied in general (on a per-node basis).
228+
return null
229+
}
230+
222231
for (let child of isolatedNode.nodes) {
223232
// Only some variants wrap children in rules. For example, the `force`
224233
// variant is a noop on the AST. And the `has` variant modifies the

packages/tailwindcss/src/variants.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,30 @@ test('not', async () => {
16441644
}
16451645
}
16461646
}
1647+
@variant parallel-style-rules {
1648+
&:hover {
1649+
@slot;
1650+
}
1651+
&:focus {
1652+
@slot;
1653+
}
1654+
}
1655+
@variant parallel-at-rules {
1656+
@media foo {
1657+
@slot;
1658+
}
1659+
@media bar {
1660+
@slot;
1661+
}
1662+
}
1663+
@variant parallel-mixed-rules {
1664+
&:hover {
1665+
@slot;
1666+
}
1667+
@media bar {
1668+
@slot;
1669+
}
1670+
}
16471671
@tailwind utilities;
16481672
`,
16491673
[
@@ -1660,6 +1684,10 @@ test('not', async () => {
16601684
'not-multiple-media-conditions:flex',
16611685
'not-starting:flex',
16621686

1687+
'not-parallel-style-rules:flex',
1688+
'not-parallel-at-rules:flex',
1689+
'not-parallel-mixed-rules:flex',
1690+
16631691
// The following built-in variants don't have not-* versions because
16641692
// there is no sensible negative version of them.
16651693

0 commit comments

Comments
 (0)