File tree Expand file tree Collapse file tree
packages/docusaurus-plugin-css-cascade-layers/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,9 +39,8 @@ describe('PostCssPluginWrapInLayer', () => {
3939 flipPlugin ,
4040 ] ) . process ( 'a{left:var(--width)}' , { from : '/site/file.css' } ) ;
4141
42- // Bug: the inserted fallback isn't flipped
4342 expect ( result . css ) . toMatchInlineSnapshot (
44- `"@layer myLayer{a{left :1px;right:var(--width)}}"` ,
43+ `"@layer myLayer{a{right :1px;right:var(--width)}}"` ,
4544 ) ;
4645 } ) ;
4746} ) ;
Original file line number Diff line number Diff line change 66 */
77
88import { findLayer } from './layers' ;
9- import type { Root , PluginCreator } from 'postcss' ;
9+ import type { Helpers , Root , PluginCreator } from 'postcss' ;
1010import type { PluginOptions } from './options' ;
1111
12- function wrapCssRootInLayer ( root : Root , layer : string ) : void {
13- const rootBefore = root . clone ( ) ;
14- root . removeAll ( ) ;
15- root . append ( {
16- type : 'atrule' ,
17- name : 'layer' ,
18- params : layer ,
19- nodes : rootBefore . nodes ,
20- } ) ;
12+ function wrapCssRootInLayer (
13+ root : Root ,
14+ layer : string ,
15+ { AtRule} : Helpers ,
16+ ) : void {
17+ const layerAtRule = new AtRule ( { name : 'layer' , params : layer } ) ;
18+ layerAtRule . append ( root . nodes ) ;
19+ root . append ( layerAtRule ) ;
2120}
2221
2322export const PostCssPluginWrapInLayer : PluginCreator < {
@@ -29,14 +28,14 @@ export const PostCssPluginWrapInLayer: PluginCreator<{
2928 const layers = Object . entries ( options . layers ) ;
3029 return {
3130 postcssPlugin : 'postcss-wrap-in-layer' ,
32- Once ( root ) {
31+ Once ( root , helpers ) {
3332 const filePath = root . source ?. input . file ;
3433 if ( ! filePath ) {
3534 return ;
3635 }
3736 const layer = findLayer ( filePath , layers ) ;
3837 if ( layer ) {
39- wrapCssRootInLayer ( root , layer ) ;
38+ wrapCssRootInLayer ( root , layer , helpers ) ;
4039 }
4140 } ,
4241 } ;
You can’t perform that action at this time.
0 commit comments