@@ -1453,6 +1453,7 @@ export class CSSGenerator {
14531453 private screenBreakpoints : Map < string , string >
14541454 private noMatchCache : Set < string > = new Set ( )
14551455 private usedKeyframes : Set < string > = new Set ( )
1456+ private variantHandledCache : Map < string , boolean > = new Map ( )
14561457 // While expanding a shortcut, rules emit under the shortcut's own class
14571458 // name (with variants applied to it: `.btn:hover`) instead of the
14581459 // sub-utility's selector, which the markup never carries.
@@ -2051,7 +2052,38 @@ export class CSSGenerator {
20512052 /**
20522053 * Add a CSS rule with variants applied
20532054 */
2055+ /**
2056+ * A variant the generator has no handler for must drop the whole rule.
2057+ * Previously an unknown variant was silently ignored, so a typo like
2058+ * `hoveer:flex` emitted `.hoveer\:flex { display: flex; }` — an
2059+ * always-on rule instead of nothing.
2060+ */
2061+ private isVariantHandled ( variant : string ) : boolean {
2062+ const cached = this . variantHandledCache . get ( variant )
2063+ if ( cached !== undefined )
2064+ return cached
2065+ const known
2066+ = VARIANT_SELECTORS [ variant ] !== undefined
2067+ || PREFIX_VARIANTS [ variant ] !== undefined
2068+ || NOT_VARIANT_SELECTORS [ variant ] !== undefined
2069+ || this . screenBreakpoints . has ( variant )
2070+ || ( variant . startsWith ( 'max-' ) && this . screenBreakpoints . has ( variant . slice ( 4 ) ) )
2071+ || ( variant . startsWith ( '@' ) && this . screenBreakpoints . has ( variant . slice ( 1 ) ) )
2072+ || variant . startsWith ( 'group-' ) || variant . startsWith ( 'group/' )
2073+ || variant . startsWith ( 'peer-' ) || variant . startsWith ( 'peer/' )
2074+ || variant . startsWith ( 'has-' ) || variant . startsWith ( 'aria-' ) || variant . startsWith ( 'data-' )
2075+ || variant . startsWith ( 'supports-' )
2076+ || ( variant . startsWith ( '[' ) && variant . endsWith ( ']' ) )
2077+ || [ 'print' , 'motion-safe' , 'motion-reduce' , 'contrast-more' , 'contrast-less' , 'landscape' , 'portrait' , 'forced-colors' ] . includes ( variant )
2078+ this . variantHandledCache . set ( variant , known )
2079+ return known
2080+ }
2081+
20542082 private addRule ( parsed : ParsedClass , properties : Record < string , string > , childSelector ?: string , pseudoElement ?: string ) : void {
2083+ for ( let i = 0 ; i < parsed . variants . length ; i ++ ) {
2084+ if ( ! this . isVariantHandled ( parsed . variants [ i ] ) )
2085+ return
2086+ }
20552087 // Use cached selector if available. Shortcut expansion changes the base
20562088 // selector for the same parsed class, so it needs its own cache slot.
20572089 const cacheKey = this . shortcutSelectorRaw === null
@@ -2118,6 +2150,17 @@ export class CSSGenerator {
21182150 for ( let i = 0 ; i < variantsLen ; i ++ ) {
21192151 const variant = variants [ i ]
21202152
2153+ // Arbitrary selector variants: [&>li]:, [&_p]:, [&:hover]: — the &
2154+ // stands for the selector built so far. Underscores become spaces
2155+ // (descendant combinators). [@media...] is handled by getMediaQuery.
2156+ if ( variant . charCodeAt ( 0 ) === 91 && variant . charCodeAt ( variant . length - 1 ) === 93 ) {
2157+ const inner = variant . slice ( 1 , - 1 ) . replace ( / _ / g, ' ' )
2158+ if ( inner . includes ( '&' ) ) {
2159+ selector = inner . replace ( / & / g, selector )
2160+ }
2161+ continue
2162+ }
2163+
21212164 // Try suffix selector lookup first (most common case)
21222165 const suffixSelector = VARIANT_SELECTORS [ variant ]
21232166 if ( suffixSelector !== undefined ) {
@@ -2288,6 +2331,15 @@ export class CSSGenerator {
22882331 const variant = variants [ i ]
22892332 const firstChar = variant . charCodeAt ( 0 )
22902333
2334+ // Arbitrary media variants: [@media(min-width:900px)]: — the inner
2335+ // @media condition joins the collected media conditions.
2336+ if ( firstChar === 91 && variant . startsWith ( '[@media' ) && variant . endsWith ( ']' ) ) {
2337+ const condition = variant . slice ( 1 , - 1 ) . replace ( / _ / g, ' ' ) . slice ( '@media' . length ) . trim ( )
2338+ if ( condition )
2339+ mediaConditions . push ( condition )
2340+ continue
2341+ }
2342+
22912343 // Container queries (@sm, @md, @lg, etc.) - '@' = 64
22922344 if ( firstChar === 64 ) {
22932345 const breakpointKey = variant . slice ( 1 )
0 commit comments