@@ -911,3 +911,56 @@ fn test_sidebar_row_layout_full_css_regression() {
911911 println ! ( "Result length: {}" , result. len( ) ) ;
912912 assert ! ( !result. is_empty( ) ) ;
913913}
914+
915+ // ============================================================================
916+ // Regression: CSS comments before first selector must not break scoping
917+ // ============================================================================
918+
919+ #[ test]
920+ fn test_scope_first_selector_after_comment_with_space ( ) {
921+ // Comment followed by space then selector
922+ let css = "/* comment */ .foo { color: red; }" ;
923+ let expected = ".foo[contenta] { color: red; }" ;
924+ assert_css_eq ! ( shim( css, "contenta" ) , expected) ;
925+ }
926+
927+ #[ test]
928+ fn test_scope_first_selector_after_comment_with_newline ( ) {
929+ // Comment followed by newline then selector (the SCSS @import case)
930+ let css = "/* comment */\n .container { border-radius: 2px; }\n .container .tabs-group { width: 100%; }" ;
931+ let expected = ".container[contenta] { border-radius: 2px; }\n .container[contenta] .tabs-group[contenta] { width: 100%; }" ;
932+ assert_css_eq ! ( shim( css, "contenta" ) , expected) ;
933+ }
934+
935+ #[ test]
936+ fn test_scope_first_selector_after_multiline_comment ( ) {
937+ // Multi-line comment followed by selector
938+ let css = "/* multi\n line\n comment */\n .root { padding: 16px; }\n .root .child { color: red; }" ;
939+ let expected =
940+ ".root[contenta] { padding: 16px; }\n .root[contenta] .child[contenta] { color: red; }" ;
941+ assert_css_eq ! ( shim( css, "contenta" ) , expected) ;
942+ }
943+
944+ #[ test]
945+ fn test_scope_first_selector_after_multiple_comments ( ) {
946+ // Multiple comments before first selector
947+ let css = "/* comment 1 */ /* comment 2 */ .foo { color: red; }" ;
948+ let expected = ".foo[contenta] { color: red; }" ;
949+ assert_css_eq ! ( shim( css, "contenta" ) , expected) ;
950+ }
951+
952+ #[ test]
953+ fn test_newline_as_descendant_combinator ( ) {
954+ // Newline between selectors is a valid CSS descendant combinator
955+ let css = ".foo\n .bar { color: red; }" ;
956+ let expected = ".foo[contenta] .bar[contenta] { color: red; }" ;
957+ assert_css_eq ! ( shim( css, "contenta" ) , expected) ;
958+ }
959+
960+ #[ test]
961+ fn test_host_pseudo_with_newline_combinator ( ) {
962+ // :host with pseudo-selector followed by newline combinator to child
963+ let css = ":host(:hover)\n .child { color: red; }" ;
964+ let expected = "[hosta]:hover .child[contenta] { color: red; }" ;
965+ assert_css_eq ! ( shim_with_host( css, "contenta" , "hosta" ) , expected) ;
966+ }
0 commit comments