Skip to content

Commit 516c149

Browse files
Allow variant to be an at-rule without a prelude (#11589)
* Allow variant to be an at-rule without a prelude * Update changelog
1 parent bc1af02 commit 516c149

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- Sort classes using position of first matching rule ([#11504](https://github.com/tailwindlabs/tailwindcss/pull/11504))
2323
- Bump `jiti`, `lightningcss`, `fast-glob` and `browserlist` dependencies and reflect `lightningcss` related improvements in tests ([#11550](https://github.com/tailwindlabs/tailwindcss/pull/11550))
2424
- Make PostCSS plugin async to improve performance ([#11548](https://github.com/tailwindlabs/tailwindcss/pull/11548))
25+
- Allow variant to be an at-rule without a prelude ([#11589](https://github.com/tailwindlabs/tailwindcss/pull/11589))
2526

2627
### Added
2728

src/lib/setupContextUtils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ export function parseVariant(variant) {
231231
return ({ format }) => format(str)
232232
}
233233

234-
let [, name, params] = /@(.*?)( .+|[({].*)/g.exec(str)
235-
return ({ wrap }) => wrap(postcss.atRule({ name, params: params.trim() }))
234+
let [, name, params] = /@(\S*)( .+|[({].*)?/g.exec(str)
235+
return ({ wrap }) => wrap(postcss.atRule({ name, params: params?.trim() ?? '' }))
236236
})
237237
.reverse()
238238

tests/variants.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,31 @@ test('order matters and produces different behaviour', () => {
5454
})
5555

5656
describe('custom advanced variants', () => {
57+
test('at-rules without params', () => {
58+
let config = {
59+
content: [
60+
{
61+
raw: html` <div class="ogre:text-center"></div> `,
62+
},
63+
],
64+
plugins: [
65+
function ({ addVariant }) {
66+
addVariant('ogre', '@layer')
67+
},
68+
],
69+
}
70+
71+
return run('@tailwind components; @tailwind utilities', config).then((result) => {
72+
return expect(result.css).toMatchFormattedCss(css`
73+
@layer {
74+
.ogre\:text-center {
75+
text-align: center;
76+
}
77+
}
78+
`)
79+
})
80+
})
81+
5782
test('prose-headings usage on its own', () => {
5883
let config = {
5984
content: [

0 commit comments

Comments
 (0)