@@ -55,7 +55,7 @@ it('unwrap rules inside at-rules', () => {
55
55
it ( 'unwraps at-rule' , ( ) => {
56
56
run (
57
57
'a { b { @media screen { width: auto } } }' ,
58
- '@media screen { a b { width: auto } }'
58
+ '@media screen {a b { width: auto } }'
59
59
)
60
60
} )
61
61
@@ -87,6 +87,13 @@ it('unwraps at-rules', () => {
87
87
)
88
88
} )
89
89
90
+ it ( 'unwraps at-rules with interleaved properties' , ( ) => {
91
+ run (
92
+ 'a { a: 1 } a { color: red; @media screen { @supports (a: 1) { a: 1 } } background: green }' ,
93
+ 'a { a: 1 } a { color: red; } @media screen { @supports (a: 1) { a { a: 1 } } } a { background: green }'
94
+ )
95
+ } )
96
+
90
97
it ( 'do not move custom at-rules' , ( ) => {
91
98
run (
92
99
'.one { @mixin test; } .two { @phone { color: black } }' ,
@@ -171,6 +178,25 @@ it('replaces ampersands in not selector', () => {
171
178
run ( '.a { &:not(&.no) {} }' , '.a:not(.a.no) {}' )
172
179
} )
173
180
181
+ it ( 'correctly replaces tail ampersands' , ( ) => {
182
+ run ( '.a { .b & {} }' , '.b .a {}' )
183
+ } )
184
+
185
+ it ( 'correctly replaces tail ampersands that are nested further down' , ( ) => {
186
+ run ( '.a { .b { .c & {} } }' , '.c .a .b {}' )
187
+ } )
188
+
189
+ it ( 'correctly replaces tail ampersands that are nested inside ampersand rules' , ( ) => {
190
+ run ( '.a { &:hover { .b { .c & {} } } }' , '.c .a:hover .b {}' )
191
+ } )
192
+
193
+ it ( 'preserves child order when replacing tail ampersands' , ( ) => {
194
+ run (
195
+ '.a { color: red; .first {} @mixinFirst; .b & {} @mixinLast; .last {} }' ,
196
+ '.a { color: red; } .a .first {} .a { @mixinFirst; } .b .a {} .a { @mixinLast; } .a .last {}'
197
+ )
198
+ } )
199
+
174
200
it ( 'handles :host selector case' , ( ) => {
175
201
run ( ':host { &(:focus) {} }' , ':host(:focus) {}' )
176
202
} )
@@ -192,6 +218,23 @@ it('works with other visitors', () => {
192
218
expect ( out ) . toEqual ( 'a b{color:red}a .in .deep{color:blue}' )
193
219
} )
194
220
221
+ it ( 'works with other visitors #2' , ( ) => {
222
+ let css = 'a { @mixin; b {color:red} }'
223
+ let mixinPlugin = ( ) => {
224
+ return {
225
+ postcssPlugin : 'mixin' ,
226
+ AtRule : {
227
+ mixin ( node ) {
228
+ node . replaceWith ( '.in { .deep {color:blue} }' )
229
+ }
230
+ }
231
+ }
232
+ }
233
+ mixinPlugin . postcss = true
234
+ let out = postcss ( [ plugin , mixinPlugin ] ) . process ( css , { from : undefined } ) . css
235
+ expect ( out ) . toEqual ( 'a .in .deep {color:blue} a b {color:red}' )
236
+ } )
237
+
195
238
it ( 'shows clear errors on missed semicolon' , ( ) => {
196
239
let css = 'a{\n color: black\n @mixin b { }\n}\n'
197
240
expect ( ( ) => {
0 commit comments