Skip to content

Commit 1f18d20

Browse files
Handle vendor-prefixed selector functions in custom variants (#20486)
Fixes #20483. ## What changed - parse `:-moz-any()` and `:-webkit-any()` arguments as selector lists, matching their standard `:is()` counterpart - allow nesting replacement to substitute `&` inside these legacy selector functions - cover both vendor-prefixed parser forms and the reported `@custom-variant firefox (:-moz-any(&))` compilation path ## Why The selector parser treated unknown function arguments as opaque values. After the nesting changes in #20124, that meant the `&` inside `:-moz-any(&)` could not be replaced and the custom variant was emitted as a descendant selector instead. These two vendor-prefixed functions are legacy aliases for selector-list matching, so handling them alongside `:is()` keeps the change narrowly scoped. ## Validation - reproduced the regression on current `main`: `.firefox\\:underline :-moz-any(:scope)` - confirmed the new assertions fail when only the parser change is reverted - `vitest run packages/tailwindcss/src/index.test.ts packages/tailwindcss/src/selector-parser.test.ts` — 299 tests passed - Prettier check passed for all changed files - `tailwindcss` production build passed, including ESM, CJS, and declaration output --------- Co-authored-by: Robin Malfait <[email protected]>
1 parent 955d37a commit 1f18d20

4 files changed

Lines changed: 48 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5252
- Drop nested rules that put a combinator after a pseudo-element when using pseudo-element variants (e.g. `selection:*` on a utility with a nested `& > *` rule) ([#20575](https://github.com/tailwindlabs/tailwindcss/pull/20575))
5353
- Don't generate CSS for arbitrary values with unbalanced parentheses or brackets (e.g. `w-[calc(1px]` or `[--x:a[b]`) ([#20577](https://github.com/tailwindlabs/tailwindcss/pull/20577))
5454
- Canonicalization: prevent `collapse: true` from taking exponentially longer when classes are linked through a utility that sets many properties (e.g. `sr-only`) ([#20558](https://github.com/tailwindlabs/tailwindcss/pull/20558))
55+
- Ensure `&` is substituted inside `:-moz-any(…)` and `:-webkit-any(…)` in custom variants (e.g. `@custom-variant firefox (:-moz-any(&));`) ([#20486](https://github.com/tailwindlabs/tailwindcss/pull/20486))
5556

5657
## [4.3.3] - 2026-07-16
5758

‎packages/tailwindcss/src/index.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4211,6 +4211,29 @@ describe('@custom-variant', () => {
42114211
`)
42124212
})
42134213
4214+
test('vendor-prefixed selector function variant', async () => {
4215+
expect(
4216+
await run(
4217+
['firefox:underline'],
4218+
css`
4219+
@custom-variant firefox (:-moz-any(&));
4220+
4221+
@layer utilities {
4222+
@tailwind utilities;
4223+
}
4224+
`,
4225+
),
4226+
).toMatchInlineSnapshot(`
4227+
"
4228+
@layer utilities {
4229+
:-moz-any(.firefox\\:underline) {
4230+
text-decoration-line: underline;
4231+
}
4232+
}
4233+
"
4234+
`)
4235+
})
4236+
42144237
test('at-rule variant', async () => {
42154238
expect(
42164239
await run(

‎packages/tailwindcss/src/selector-parser.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,27 @@ describe('parse', () => {
284284
])
285285
})
286286

287+
it.each([':-moz-any', ':-webkit-any'])(
288+
'should parse selector lists in vendor-prefixed functions (%s)',
289+
(fn) => {
290+
expect(parse(`${fn}(&, .foo)`)).toEqual([
291+
{
292+
kind: 'function',
293+
value: fn,
294+
nodes: [
295+
{
296+
kind: 'list',
297+
nodes: [
298+
{ kind: 'selector', value: '&' },
299+
{ kind: 'selector', value: '.foo' },
300+
],
301+
},
302+
],
303+
},
304+
])
305+
},
306+
)
307+
287308
it('should handle next-children combinator', () => {
288309
expect(parse('.foo + p')).toEqual([
289310
{

‎packages/tailwindcss/src/selector-parser.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ export function parse(input: string) {
394394
node.value !== ':not' &&
395395
node.value !== ':where' &&
396396
node.value !== ':has' &&
397-
node.value !== ':is'
397+
node.value !== ':is' &&
398+
node.value !== ':-moz-any' &&
399+
node.value !== ':-webkit-any'
398400
) {
399401
// Find the end of the function call
400402
let start = i + 1

0 commit comments

Comments
 (0)