Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Ensure nested functions in selectors used with JavaScript plugins are…
… not truncated
  • Loading branch information
philipp-spiess committed Feb 25, 2025
commit 9fb7fdd2ed11ea743e5ba6b5b969880f34500a7e
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
79 changes: 79 additions & 0 deletions packages/tailwindcss/src/compat/selector-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,85 @@ 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',
},
],
},
],
},
])
})

it('parses :not(:nth-child(1))', () => {
expect(parse('&:not(:nth-child(1))')).toEqual([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is structurally identical to the :has(…) test above. Is it necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, good catch. Removed!

{
kind: 'selector',
value: '&',
},
{
kind: 'function',
value: ':not',
nodes: [
{
kind: 'function',
value: ':nth-child',
nodes: [
{
kind: 'value',
value: '1',
},
],
},
],
},
])
})
})

describe('toCss', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/tailwindcss/src/compat/selector-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down