From d8998a1998cfd73b85888e868b6ad5f807e2445c Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 11 Jul 2023 15:42:52 -0400 Subject: [PATCH 1/2] Allow variant to be an at-rule without a prelude --- src/lib/setupContextUtils.js | 4 ++-- tests/variants.test.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/lib/setupContextUtils.js b/src/lib/setupContextUtils.js index fe2191b7d5fa..00b05652af0d 100644 --- a/src/lib/setupContextUtils.js +++ b/src/lib/setupContextUtils.js @@ -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() diff --git a/tests/variants.test.js b/tests/variants.test.js index f2a2de075acd..51980d8a09dd 100644 --- a/tests/variants.test.js +++ b/tests/variants.test.js @@ -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`
`, + }, + ], + 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: [ From 01a4a4976a8e51dd86aef74918ed4cbb0eed347e Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Tue, 11 Jul 2023 15:49:21 -0400 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9265922bc08..f3897a901548 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Sort classes using position of first matching rule ([#11504](https://github.com/tailwindlabs/tailwindcss/pull/11504)) - Bump `jiti`, `lightningcss`, `fast-glob` and `browserlist` dependencies and reflect `lightningcss` related improvements in tests ([#11550](https://github.com/tailwindlabs/tailwindcss/pull/11550)) - Make PostCSS plugin async to improve performance ([#11548](https://github.com/tailwindlabs/tailwindcss/pull/11548)) +- Allow variant to be an at-rule without a prelude ([#11589](https://github.com/tailwindlabs/tailwindcss/pull/11589)) ### Added