Skip to content

Commit adac9bf

Browse files
committed
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 859d2b2 commit adac9bf

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
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Move unknown pseudo-elements outside of `:is` by default ([#11345](https://github.com/tailwindlabs/tailwindcss/pull/11345))
1717
- Escape animation names when prefixes contain special characters ([#11470](https://github.com/tailwindlabs/tailwindcss/pull/11470))
1818
- Sort classes using position of first matching rule ([#11504](https://github.com/tailwindlabs/tailwindcss/pull/11504))
19+
- Allow variant to be an at-rule without a prelude ([#11589](https://github.com/tailwindlabs/tailwindcss/pull/11589))
1920

2021
### Added
2122

src/lib/setupContextUtils.js

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

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

tests/variants.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,31 @@ crosscheck(({ stable, oxide }) => {
6666
})
6767

6868
describe('custom advanced variants', () => {
69+
test('at-rules without params', () => {
70+
let config = {
71+
content: [
72+
{
73+
raw: html` <div class="ogre:text-center"></div> `,
74+
},
75+
],
76+
plugins: [
77+
function ({ addVariant }) {
78+
addVariant('ogre', '@layer')
79+
},
80+
],
81+
}
82+
83+
return run('@tailwind components; @tailwind utilities', config).then((result) => {
84+
return expect(result.css).toMatchFormattedCss(css`
85+
@layer {
86+
.ogre\:text-center {
87+
text-align: center;
88+
}
89+
}
90+
`)
91+
})
92+
})
93+
6994
test('prose-headings usage on its own', () => {
7095
let config = {
7196
content: [

0 commit comments

Comments
 (0)