Skip to content

Commit 1e0099a

Browse files
committed
Add support for at rules
1 parent 56c320d commit 1e0099a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/lib/generateRules.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as sharedState from './sharedState'
99
import { formatVariantSelector, finalizeSelector } from '../util/formatVariantSelector'
1010
import { asClass } from '../util/nameClass'
1111
import { normalize } from '../util/dataTypes'
12+
import { parseVariant } from './setupContextUtils'
1213
import isValidArbitraryValue from '../util/isValidArbitraryValue'
1314

1415
let classNameParser = selectorParser((selectors) => {
@@ -128,8 +129,12 @@ function applyVariant(variant, matches, context) {
128129
// Register arbitrary variants
129130
if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
130131
let selector = normalize(variant.slice(1, -1))
132+
133+
// TODO: Error recovery for @supports(what:ever) -- note the absence of a space
134+
let fn = parseVariant(selector)
135+
131136
let sort = Array.from(context.variantOrder.values()).pop() << 1n
132-
context.variantMap.set(variant, [[sort, () => selector]])
137+
context.variantMap.set(variant, [[sort, fn]])
133138
context.variantOrder.set(variant, sort)
134139
}
135140

tests/arbitrary-variants.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,26 @@ test('using the important modifier', () => {
132132
`)
133133
})
134134
})
135+
136+
test('at-rules', () => {
137+
let config = {
138+
content: [{ raw: html`<div class="[@supports_(what:ever){&:hover}]:underline"></div>` }],
139+
corePlugins: { preflight: false },
140+
}
141+
142+
let input = css`
143+
@tailwind base;
144+
@tailwind components;
145+
@tailwind utilities;
146+
`
147+
148+
return run(input, config).then((result) => {
149+
expect(result.css).toMatchFormattedCss(css`
150+
${defaults}
151+
152+
.\[\&\>\*\]\:\!underline > * {
153+
text-decoration-line: underline !important;
154+
}
155+
`)
156+
})
157+
})

0 commit comments

Comments
 (0)