File tree 2 files changed +37
-8
lines changed
2 files changed +37
-8
lines changed Original file line number Diff line number Diff line change @@ -74,34 +74,36 @@ function mergeSelectors(parent, child) {
74
74
75
75
/**
76
76
* Move a child and its preceding comment(s) to after "after"
77
- * ! It is necessary to clarify the comment
78
77
*/
79
- function breakOut ( child , after ) {
78
+ function breakOut ( child , parent ) {
80
79
let changeParent = true
80
+ let lastNode = parent
81
81
82
- for ( let node of after . nodes ) {
82
+ for ( let node of parent . nodes ) {
83
83
if ( ! node . nodes ) continue
84
84
85
85
let prevNode = node . prev ( )
86
86
if ( prevNode ?. type !== 'comment' ) continue
87
87
88
- let parentRule = after . toString ( )
88
+ let parentRule = parent . toString ( )
89
89
90
90
/* Checking that the comment "describes" the rule following. Like this:
91
91
/* comment about the rule below /*
92
92
.rule {}
93
93
*/
94
- let regexp = new RegExp ( ` ${ prevNode . toString ( ) } *\n * ${ node . toString ( ) } ` )
94
+ let regexp = / [ * ] \/ * \n . * { /
95
95
96
96
if ( parentRule . match ( regexp ) ) {
97
97
changeParent = false
98
- after . after ( node ) . after ( prevNode )
98
+ lastNode . after ( node ) . after ( prevNode )
99
+
100
+ lastNode = node
99
101
}
100
102
}
101
103
102
104
// It is necessary if the above child has never been moved
103
105
if ( changeParent ) {
104
- after . after ( child )
106
+ parent . after ( child )
105
107
}
106
108
107
109
return child
Original file line number Diff line number Diff line change @@ -608,12 +608,39 @@ test("Save the parent's comment", () => {
608
608
run ( 'a { /*i*/ b {} }' , 'a { /*i*/ } a b {}' )
609
609
} )
610
610
611
+ test ( "Save the parent's comment" , ( ) => {
612
+ run (
613
+ `
614
+ div {
615
+ /* Comment with ^ $ . | ? * + () */
616
+ &[data-roots-all^=1] * #id .class {}
617
+ }` ,
618
+ '/* Comment with ^ $ . | ? * + () */ div[data-roots-all^=1] * #id .class {}' )
619
+ } )
620
+
621
+ // !
622
+ // test("Save the parent's comment with newline", () => {
623
+ // run(
624
+ // `
625
+ // a {
626
+ // /*i*/
627
+
628
+ // /*i2*/
629
+ // b {}
630
+ // /*i3*/
631
+ // s {}
632
+ // }`,
633
+ // `a { /*i*/ } /*i2*/ a b {} /*i3*/ a s {}`
634
+ // )
635
+ // })
636
+
611
637
test ( "Save the parent's comment with newline" , ( ) => {
612
638
run (
613
639
`a {
614
640
/*i*/
615
641
616
- b {} }` ,
642
+ b {}
643
+ }` ,
617
644
`a { /*i*/ } a b {}`
618
645
)
619
646
} )
You can’t perform that action at this time.
0 commit comments