|
42 | 42 | test_valid_child('@mixin --m() { @result { @starting-style {} } }', '@starting-style'); |
43 | 43 | test_valid_child('@mixin --m() { @result { @scope (.foo) {} } }', '@scope'); |
44 | 44 | test_valid_child('@mixin --m() { @result { @scope {} } }', '@scope (implicit)'); |
| 45 | + |
| 46 | + // @layer is invalid inside mixins, so it must be dropped at any depth. The |
| 47 | + // green sibling rule must survive, proving only the @layer was dropped and |
| 48 | + // not its enclosing container. |
| 49 | + function test_layer_dropped(css, description) { |
| 50 | + test(() => { |
| 51 | + let sheet = new CSSStyleSheet(); |
| 52 | + sheet.replaceSync(css); |
| 53 | + assert_equals(sheet.cssRules.length, 1, 'mixin is present'); |
| 54 | + let mixin_text = sheet.cssRules[0].cssText; |
| 55 | + assert_true(mixin_text.includes('color: green'), `sibling rule retained: ${mixin_text}`); |
| 56 | + assert_false(/@layer/i.test(mixin_text), `@layer dropped: ${mixin_text}`); |
| 57 | + }, `@layer is dropped within ${description}`); |
| 58 | + } |
| 59 | + |
| 60 | + test_layer_dropped('@mixin --m() { @result { @layer bar; div { color: green } } }', '@result (statement)'); |
| 61 | + test_layer_dropped('@mixin --m() { @result { @layer bar {} div { color: green } } }', '@result (block)'); |
| 62 | + test_layer_dropped('@mixin --m() { @result { div { @layer bar; color: green } } }', 'a nested style rule'); |
| 63 | + test_layer_dropped('@mixin --m() { @result { @media (width) { @layer bar; div { color: green } } } }', '@media'); |
| 64 | + test_layer_dropped('@mixin --m() { @result { @supports (width: 0) { @layer bar; div { color: green } } } }', '@supports'); |
| 65 | + test_layer_dropped('@mixin --m() { @result { @container (width) { @layer bar; div { color: green } } } }', '@container'); |
| 66 | + test_layer_dropped('@mixin --m() { @result { @scope (.foo) { @layer bar; div { color: green } } } }', '@scope'); |
| 67 | + test_layer_dropped('@mixin --m() { @media (width) { @layer bar; @result { div { color: green } } } }', 'a body-level @media'); |
| 68 | + test_layer_dropped('@mixin --m() { @supports (width: 0) { @layer bar; @result { div { color: green } } } }', 'a body-level @supports'); |
| 69 | + test_layer_dropped('@mixin --m() { @container (width) { @layer bar; @result { div { color: green } } } }', 'a body-level @container'); |
45 | 70 | </script> |
46 | 71 |
|
47 | 72 | </body> |
|
0 commit comments