@@ -66,26 +66,32 @@ function pickComment (comment, after) {
66
66
}
67
67
}
68
68
69
- function atruleChilds ( rule , atrule , bubbling ) {
70
- let children = [ ]
71
- atrule . each ( child => {
72
- if ( child . type === 'comment' ) {
73
- children . push ( child )
74
- } else if ( child . type === 'decl' ) {
75
- children . push ( child )
76
- } else if ( child . type === 'rule' && bubbling ) {
77
- child . selectors = selectors ( rule , child )
78
- } else if ( child . type === 'atrule' ) {
79
- atruleChilds ( rule , child , bubbling )
80
- }
81
- } )
82
- if ( bubbling ) {
83
- if ( children . length ) {
84
- let clone = rule . clone ( { nodes : [ ] } )
85
- for ( let child of children ) {
86
- clone . append ( child )
69
+ function createFnAtruleChilds ( bubble ) {
70
+ return function atruleChilds ( rule , atrule , bubbling ) {
71
+ let children = [ ]
72
+ atrule . each ( child => {
73
+ if ( child . type === 'comment' ) {
74
+ children . push ( child )
75
+ } else if ( child . type === 'decl' ) {
76
+ children . push ( child )
77
+ } else if ( child . type === 'rule' && bubbling ) {
78
+ child . selectors = selectors ( rule , child )
79
+ } else if ( child . type === 'atrule' ) {
80
+ if ( child . nodes && bubble [ child . name ] ) {
81
+ atruleChilds ( rule , child , true )
82
+ } else {
83
+ children . push ( child )
84
+ }
85
+ }
86
+ } )
87
+ if ( bubbling ) {
88
+ if ( children . length ) {
89
+ let clone = rule . clone ( { nodes : [ ] } )
90
+ for ( let child of children ) {
91
+ clone . append ( child )
92
+ }
93
+ atrule . prepend ( clone )
87
94
}
88
- atrule . prepend ( clone )
89
95
}
90
96
}
91
97
}
@@ -120,6 +126,7 @@ function atruleNames (defaults, custom) {
120
126
121
127
module . exports = ( opts = { } ) => {
122
128
let bubble = atruleNames ( [ 'media' , 'supports' ] , opts . bubble )
129
+ let atruleChilds = createFnAtruleChilds ( bubble )
123
130
let unwrap = atruleNames (
124
131
[
125
132
'document' ,
0 commit comments