@@ -163,15 +163,17 @@ function applyVariant(variant, matches, context) {
163
163
164
164
let container = postcss . root ( { nodes : [ rule . clone ( ) ] } )
165
165
166
- for ( let [ variantSort , variantFunction ] of variantFunctionTuples ) {
167
- let clone = container . clone ( )
166
+ for ( let [ variantSort , variantFunction , containerFromArray ] of variantFunctionTuples ) {
167
+ let clone = containerFromArray ?? container . clone ( )
168
168
let collectedFormats = [ ]
169
169
170
- let originals = new Map ( )
171
-
172
170
function prepareBackup ( ) {
173
- if ( originals . size > 0 ) return // Already prepared, chicken out
174
- clone . walkRules ( ( rule ) => originals . set ( rule , rule . selector ) )
171
+ // Already prepared, chicken out
172
+ if ( clone . raws . neededBackup ) {
173
+ return
174
+ }
175
+ clone . raws . neededBackup = true
176
+ clone . walkRules ( ( rule ) => ( rule . raws . originalSelector = rule . selector ) )
175
177
}
176
178
177
179
function modifySelectors ( modifierFunction ) {
@@ -231,6 +233,10 @@ function applyVariant(variant, matches, context) {
231
233
// reserving additional X places for these 'unknown' variants in between.
232
234
variantSort | BigInt ( idx << ruleWithVariant . length ) ,
233
235
variantFunction ,
236
+
237
+ // If the clone has been modified we have to pass that back
238
+ // though so each rule can use the modified container
239
+ clone . clone ( ) ,
234
240
] )
235
241
}
236
242
continue
@@ -244,13 +250,15 @@ function applyVariant(variant, matches, context) {
244
250
continue
245
251
}
246
252
247
- // We filled the `originals` , therefore we assume that somebody touched
253
+ // We had to backup selectors , therefore we assume that somebody touched
248
254
// `container` or `modifySelectors`. Let's see if they did, so that we
249
255
// can restore the selectors, and collect the format strings.
250
- if ( originals . size > 0 ) {
256
+ if ( clone . raws . neededBackup ) {
257
+ delete clone . raws . neededBackup
251
258
clone . walkRules ( ( rule ) => {
252
- if ( ! originals . has ( rule ) ) return
253
- let before = originals . get ( rule )
259
+ let before = rule . raws . originalSelector
260
+ if ( ! before ) return
261
+ delete rule . raws . originalSelector
254
262
if ( before === rule . selector ) return // No mutation happened
255
263
256
264
let modified = rule . selector
0 commit comments