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
Allow variant to be an at-rule without a prelude
  • Loading branch information
thecrypticace committed Jul 11, 2023
commit d8998a1998cfd73b85888e868b6ad5f807e2445c
4 changes: 2 additions & 2 deletions src/lib/setupContextUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,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 @@ -54,6 +54,31 @@ test('order matters and produces different behaviour', () => {
})

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