Skip to content

Commit

Permalink
Allow variant to be an at-rule without a prelude (#11589)
Browse files Browse the repository at this point in the history
* Allow variant to be an at-rule without a prelude

* Update changelog
  • Loading branch information
thecrypticace committed Jul 13, 2023
1 parent 859d2b2 commit adac9bf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Move unknown pseudo-elements outside of `:is` by default ([#11345](https://github.com/tailwindlabs/tailwindcss/pull/11345))
- Escape animation names when prefixes contain special characters ([#11470](https://github.com/tailwindlabs/tailwindcss/pull/11470))
- Sort classes using position of first matching rule ([#11504](https://github.com/tailwindlabs/tailwindcss/pull/11504))
- Allow variant to be an at-rule without a prelude ([#11589](https://github.com/tailwindlabs/tailwindcss/pull/11589))

### Added

Expand Down
4 changes: 2 additions & 2 deletions src/lib/setupContextUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ export function parseVariant(variant) {
return ({ format }) => format(str)
}

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

Expand Down
25 changes: 25 additions & 0 deletions tests/variants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,31 @@ crosscheck(({ stable, oxide }) => {
})

describe('custom advanced variants', () => {
test('at-rules without params', () => {
let config = {
content: [
{
raw: html` <div class="ogre:text-center"></div> `,
},
],
plugins: [
function ({ addVariant }) {
addVariant('ogre', '@layer')
},
],
}

return run('@tailwind components; @tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
@layer {
.ogre\:text-center {
text-align: center;
}
}
`)
})
})

test('prose-headings usage on its own', () => {
let config = {
content: [
Expand Down

0 comments on commit adac9bf

Please sign in to comment.