diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b9687e148d8..0863058bffb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix an issue where `@reference "…"` would sometimes omit keyframe animations ([#16774](https://github.com/tailwindlabs/tailwindcss/pull/16774)) - Ensure `z-*!` utilities are property marked as `!important` ([#16795](https://github.com/tailwindlabs/tailwindcss/pull/16795)) - Read UTF-8 CSS files that start with a byte-order mark (BOM) ([#16796](https://github.com/tailwindlabs/tailwindcss/pull/16796)) +- Ensure nested functions in selectors used with JavaScript plugins are not truncated ([#16802](https://github.com/tailwindlabs/tailwindcss/pull/16802)) ## [4.0.8] - 2025-02-21 diff --git a/packages/tailwindcss/src/compat/selector-parser.test.ts b/packages/tailwindcss/src/compat/selector-parser.test.ts index 1c0b808b08d1..f995c9de72c5 100644 --- a/packages/tailwindcss/src/compat/selector-parser.test.ts +++ b/packages/tailwindcss/src/compat/selector-parser.test.ts @@ -77,6 +77,60 @@ describe('parse', () => { }, ]) }) + + it('parses &:has(.child:nth-child(2))', () => { + expect(parse('&:has(.child:nth-child(2))')).toEqual([ + { + kind: 'selector', + value: '&', + }, + { + kind: 'function', + value: ':has', + nodes: [ + { + kind: 'selector', + value: '.child', + }, + { + kind: 'function', + value: ':nth-child', + nodes: [ + { + kind: 'value', + value: '2', + }, + ], + }, + ], + }, + ]) + }) + + it('parses &:has(:nth-child(2))', () => { + expect(parse('&:has(:nth-child(2))')).toEqual([ + { + kind: 'selector', + value: '&', + }, + { + kind: 'function', + value: ':has', + nodes: [ + { + kind: 'function', + value: ':nth-child', + nodes: [ + { + kind: 'value', + value: '2', + }, + ], + }, + ], + }, + ]) + }) }) describe('toCss', () => { diff --git a/packages/tailwindcss/src/compat/selector-parser.ts b/packages/tailwindcss/src/compat/selector-parser.ts index 341f9b581379..a5ea5e098194 100644 --- a/packages/tailwindcss/src/compat/selector-parser.ts +++ b/packages/tailwindcss/src/compat/selector-parser.ts @@ -300,7 +300,11 @@ export function parse(input: string) { buffer = '' i = end - ast.push(node) + if (parent) { + parent.nodes.push(node) + } else { + ast.push(node) + } break }