Skip to content

Commit 9fb7fdd

Browse files
Ensure nested functions in selectors used with JavaScript plugins are not truncated
1 parent 294952f commit 9fb7fdd

File tree

3 files changed

+85
-1
lines changed

3 files changed

+85
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- Fix an issue where `@reference "…"` would sometimes omit keyframe animations ([#16774](https://github.com/tailwindlabs/tailwindcss/pull/16774))
2222
- Ensure `z-*!` utilities are property marked as `!important` ([#16795](https://github.com/tailwindlabs/tailwindcss/pull/16795))
2323
- Read UTF-8 CSS files that start with a byte-order mark (BOM) ([#16796](https://github.com/tailwindlabs/tailwindcss/pull/16796))
24+
- Ensure nested functions in selectors used with JavaScript plugins are not truncated ([#16802](https://github.com/tailwindlabs/tailwindcss/pull/16802))
2425

2526
## [4.0.8] - 2025-02-21
2627

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,85 @@ describe('parse', () => {
7777
},
7878
])
7979
})
80+
81+
it('parses &:has(.child:nth-child(2))', () => {
82+
expect(parse('&:has(.child:nth-child(2))')).toEqual([
83+
{
84+
kind: 'selector',
85+
value: '&',
86+
},
87+
{
88+
kind: 'function',
89+
value: ':has',
90+
nodes: [
91+
{
92+
kind: 'selector',
93+
value: '.child',
94+
},
95+
{
96+
kind: 'function',
97+
value: ':nth-child',
98+
nodes: [
99+
{
100+
kind: 'value',
101+
value: '2',
102+
},
103+
],
104+
},
105+
],
106+
},
107+
])
108+
})
109+
110+
it('parses &:has(:nth-child(2))', () => {
111+
expect(parse('&:has(:nth-child(2))')).toEqual([
112+
{
113+
kind: 'selector',
114+
value: '&',
115+
},
116+
{
117+
kind: 'function',
118+
value: ':has',
119+
nodes: [
120+
{
121+
kind: 'function',
122+
value: ':nth-child',
123+
nodes: [
124+
{
125+
kind: 'value',
126+
value: '2',
127+
},
128+
],
129+
},
130+
],
131+
},
132+
])
133+
})
134+
135+
it('parses :not(:nth-child(1))', () => {
136+
expect(parse('&:not(:nth-child(1))')).toEqual([
137+
{
138+
kind: 'selector',
139+
value: '&',
140+
},
141+
{
142+
kind: 'function',
143+
value: ':not',
144+
nodes: [
145+
{
146+
kind: 'function',
147+
value: ':nth-child',
148+
nodes: [
149+
{
150+
kind: 'value',
151+
value: '1',
152+
},
153+
],
154+
},
155+
],
156+
},
157+
])
158+
})
80159
})
81160

82161
describe('toCss', () => {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,11 @@ export function parse(input: string) {
300300
buffer = ''
301301
i = end
302302

303-
ast.push(node)
303+
if (parent) {
304+
parent.nodes.push(node)
305+
} else {
306+
ast.push(node)
307+
}
304308

305309
break
306310
}

0 commit comments

Comments
 (0)