File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
packages-presets/transformer-directives/src Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -71,10 +71,16 @@ export async function transformDirectives(
71
71
72
72
await Promise . all ( stack )
73
73
74
- // Remove empty blocks
75
74
const oldCode = code . toString ( )
75
+ // transformDirectives has recursive behavior, only for the last call
76
76
if ( ! isHasApply ( oldCode ) ) {
77
- const newCode = oldCode . replace ( / [ ^ { } ] * \{ \s * \} \s * / g, '' )
77
+ const newCode = oldCode . replace ( / ( [ ^ { } ] + ) \{ \s * \} \s * / g, ( m , selector ) => {
78
+ // Only remove empty rules with valid selectors
79
+ if ( / ^ [ \s \w \- . , # : [ \] = * " ' > ~ + ^ $ | ( ) \\ ] + $ / . test ( selector . trim ( ) ) )
80
+ return ''
81
+ return m
82
+ } )
83
+
78
84
if ( newCode !== oldCode )
79
85
code . update ( 0 , code . original . length , newCode )
80
86
}
Original file line number Diff line number Diff line change @@ -655,6 +655,28 @@ div {
655
655
` )
656
656
} )
657
657
658
+ it ( '@apply with empty block comments' , async ( ) => {
659
+ const result = await transform (
660
+ `
661
+ .aaa {
662
+ @apply text-blue-500;
663
+ /* {} empty curly brace in comment will lead to wrong parsing */
664
+ font-weight: 900;
665
+ }
666
+ ` ,
667
+ )
668
+ expect ( result )
669
+ . toMatchInlineSnapshot ( `
670
+ ".aaa {
671
+ --un-text-opacity: 1;
672
+ color: rgb(59 130 246 / var(--un-text-opacity));
673
+ /* {} empty curly brace in comment will lead to wrong parsing */
674
+ font-weight: 900;
675
+ }
676
+ "
677
+ ` )
678
+ } )
679
+
658
680
it ( '@apply selector group' , async ( ) => {
659
681
const result = await transform (
660
682
'.btn { @apply: sgroup:bg-orange }' ,
You can’t perform that action at this time.
0 commit comments