@@ -269,24 +269,19 @@ export default class Stylesheet {
269
269
270
270
this . has_styles = true ;
271
271
272
- const stack : Array < Rule | Atrule > = [ ] ;
272
+ const stack : Array < Atrule > = [ ] ;
273
+ let depth = 0 ;
273
274
let current_atrule : Atrule = null ;
274
275
275
276
walk ( ast . css , {
276
277
enter : ( node : Node ) => {
277
278
if ( node . type === 'Atrule' ) {
278
- const last = stack [ stack . length - 1 ] ;
279
-
280
279
const atrule = new Atrule ( node ) ;
281
280
stack . push ( atrule ) ;
282
281
283
- // this is an awkward special case — @apply (and
284
- // possibly other future constructs)
285
- if ( last && ! ( last instanceof Atrule ) ) return ;
286
-
287
282
if ( current_atrule ) {
288
283
current_atrule . children . push ( atrule ) ;
289
- } else {
284
+ } else if ( depth <= 1 ) {
290
285
this . children . push ( atrule ) ;
291
286
}
292
287
@@ -303,26 +298,24 @@ export default class Stylesheet {
303
298
304
299
if ( node . type === 'Rule' ) {
305
300
const rule = new Rule ( node , this , current_atrule ) ;
306
- stack . push ( rule ) ;
307
301
308
302
if ( current_atrule ) {
309
303
current_atrule . children . push ( rule ) ;
310
- } else {
304
+ } else if ( depth <= 1 ) {
311
305
this . children . push ( rule ) ;
312
306
}
313
307
}
308
+
309
+ depth += 1 ;
314
310
} ,
315
311
316
312
leave : ( node : Node ) => {
317
- if ( node . type === 'Rule' || node . type === 'Atrule' ) stack . pop ( ) ;
318
313
if ( node . type === 'Atrule' ) {
319
- current_atrule = null ;
320
- for ( let i = stack . length - 1 ; i >= 0 ; i -- ) {
321
- if ( stack [ i ] instanceof Atrule ) {
322
- current_atrule = stack [ i ] as Atrule ;
323
- }
324
- }
314
+ stack . pop ( ) ;
315
+ current_atrule = stack [ stack . length - 1 ] ;
325
316
}
317
+
318
+ depth -= 1 ;
326
319
}
327
320
} ) ;
328
321
} else {
0 commit comments