@@ -39,7 +39,7 @@ import chokidar, { FSWatcher } from 'chokidar'
39
39
import findUp from 'find-up'
40
40
import minimatch from 'minimatch'
41
41
import resolveFrom , { setPnpApi } from './util/resolveFrom'
42
- import { /*postcssFallback,*/ Result } from 'postcss'
42
+ import { /*postcssFallback,*/ AtRule , Container , Node , Result } from 'postcss'
43
43
// import tailwindcssFallback from 'tailwindcss'
44
44
// import resolveConfigFallback from 'tailwindcss/resolveConfig'
45
45
import Module from 'module'
@@ -1096,6 +1096,10 @@ function runPlugin(
1096
1096
} catch ( _ ) { }
1097
1097
}
1098
1098
1099
+ function isAtRule ( node : Node ) : node is AtRule {
1100
+ return node . type === 'atrule'
1101
+ }
1102
+
1099
1103
function getVariants ( state : State ) : Record < string , string > {
1100
1104
if ( state . jit ) {
1101
1105
function escape ( className : string ) : string {
@@ -1153,18 +1157,36 @@ function getVariants(state: State): Record<string, string> {
1153
1157
let definitions = [ ]
1154
1158
1155
1159
for ( let fn of fns ) {
1160
+ let definition : string
1156
1161
let container = root . clone ( )
1157
- fn ( {
1162
+ let returnValue = fn ( {
1158
1163
container,
1159
1164
separator : state . separator ,
1160
1165
modifySelectors,
1166
+ format : ( def : string ) => {
1167
+ definition = def . replace ( / : m e r g e \( ( [ ^ ) ] + ) \) / g, '$1' )
1168
+ } ,
1169
+ wrap : ( rule : Container ) => {
1170
+ if ( isAtRule ( rule ) ) {
1171
+ definition = `@${ rule . name } ${ rule . params } `
1172
+ }
1173
+ } ,
1161
1174
} )
1162
1175
1176
+ if ( ! definition ) {
1177
+ definition = returnValue
1178
+ }
1179
+
1180
+ if ( definition ) {
1181
+ definitions . push ( definition )
1182
+ continue
1183
+ }
1184
+
1163
1185
container . walkDecls ( ( decl ) => {
1164
1186
decl . remove ( )
1165
1187
} )
1166
1188
1167
- let definition = container
1189
+ definition = container
1168
1190
. toString ( )
1169
1191
. replace ( `.${ escape ( `${ variantName } :${ placeholder } ` ) } ` , '&' )
1170
1192
. replace ( / (?< ! \\ ) [ { } ] / g, '' )
0 commit comments