Repository: swc-project/swc (rust)

Issue:
The css module is not edited as expected
### Describe the bug

The css module is not edited as expected
Problem code
https://github.com/swc-project/swc/blob/6c3ff01a53405550c74c71ea8761faa167950f43/crates/swc_css_modules/src/lib.rs#L522-L544

### Input code

```typescript
use swc_core::common::FileName;
use swc_core::common::input::SourceFileInput;
use swc_core::css::ast::{ComplexSelector, ComplexSelectorChildren, PseudoClassSelectorChildren, SubclassSelector};
use swc_core::css::codegen::{CodegenConfig, CodeGenerator, Emit};
use swc_core::css::codegen::writer::basic::{BasicCssWriter, BasicCssWriterConfig};
use swc_core::css::parser::lexer::Lexer;
use swc_core::css::parser::parser::{Parser, ParserConfig};
use swc_core::ecma::atoms::JsWord;
use swc_css_visit::VisitMut;
use swc_css_visit::VisitMutWith;
use swc_core::common::{util::take::Take};

pub struct ModulesTransformConfig {

}

impl swc_core::css::modules::TransformConfig for ModulesTransformConfig {
    fn new_name_for(&self, local: &JsWord) -> JsWord {
        dbg!(local);
    local.clone().into()
        }
}



fn main() {
    let mut cm: swc_core::common::SourceMap = Default::default();
    let fm = cm.new_source_file(FileName::Custom("a.css".to_string())
                                , ":global(.a):hover{color:'red';}".to_string());
    let lexer = Lexer::new(SourceFileInput::from(&*fm)
                           , ParserConfig {
            css_modules: true,
            legacy_ie: true,
            ..Default::default()
        });
    let mut parser = Parser::new(lexer,
                                 ParserConfig {
                                     css_modules: true,
                                     legacy_ie: true,
                                     ..Default::default()
                                 });
    let mut stylesheet = parser.parse_all();
    // dbg!(&stylesheet);
   let mut ss= stylesheet.as_mut().unwrap();
    // ss.visit_mut_with(&mut F{});

    swc_core::css::modules::compile( ss,ModulesTransformConfig{});
    // dbg!(&stylesheet);
    let mut output = String::new();

    let wr = BasicCssWriter::new(&mut output,Default::default(),BasicCssWriterConfig::default());

    let mut gen = CodeGenerator::new(wr,CodegenConfig{
        minify:false
    });
    gen.emit(&stylesheet.unwrap()).expect("TODO: panic message");

    dbg!(output);
}
```


### Config

_No response_

### Playground link

_No response_

### Expected behavior

.a:hover{color:red}

### Actual behavior

.a{color:red}

### Version

swc_core = { version = "0.76.18",

### Additional context

_No response_

Pull request description:
fix(css/modules): Don't drop the correct selector
**Related issue:**

 - Closes #7447.

Patch:
diff --git a/crates/swc_css_modules/src/lib.rs b/crates/swc_css_modules/src/lib.rs
index 16f5b06668..21e13cb5bd 100644
--- a/crates/swc_css_modules/src/lib.rs
+++ b/crates/swc_css_modules/src/lib.rs
@@ -502,11 +502,7 @@ where
                                             complex_selector.children.clone();
                                         prepend_left_subclass_selectors(
                                             &mut complex_selector_children,
-                                            selector
-                                                .subclass_selectors
-                                                .split_at(sel_index)
-                                                .0
-                                                .to_vec(),
+                                            selector.subclass_selectors.split_at(sel_index),
                                         );
                                         new_children.extend(complex_selector_children);
 
@@ -529,11 +525,7 @@ where
                                             complex_selector.children.clone();
                                         prepend_left_subclass_selectors(
                                             &mut complex_selector_children,
-                                            selector
-                                                .subclass_selectors
-                                                .split_at(sel_index)
-                                                .0
-                                                .to_vec(),
+                                            selector.subclass_selectors.split_at(sel_index),
                                         );
                                         new_children.extend(complex_selector_children);
                                     }
@@ -651,11 +643,16 @@ fn process_local<C>(
 
 fn prepend_left_subclass_selectors(
     complex_selector_children: &mut [ComplexSelectorChildren],
-    left_sels: Vec<SubclassSelector>,
+    sels: (&[SubclassSelector], &[SubclassSelector]),
 ) {
     if let Some(ComplexSelectorChildren::CompoundSelector(first)) =
         complex_selector_children.get_mut(0)
     {
-        first.subclass_selectors = [left_sels, first.subclass_selectors.take()].concat();
+        first.subclass_selectors = [
+            sels.0.to_vec(),
+            first.subclass_selectors.take(),
+            sels.1[1..].to_vec(),
+        ]
+        .concat();
     }
 }


Test patch:
diff --git a/crates/swc_css_modules/tests/fixture/issues/issuse-7447.compiled.css b/crates/swc_css_modules/tests/fixture/issues/issuse-7447.compiled.css
new file mode 100644
index 0000000000..bc0f3dc897
--- /dev/null
+++ b/crates/swc_css_modules/tests/fixture/issues/issuse-7447.compiled.css
@@ -0,0 +1,6 @@
+.a:hover {
+  color: blue;
+}
+.__local__a.b {
+  color: red;
+}
diff --git a/crates/swc_css_modules/tests/fixture/issues/issuse-7447.css b/crates/swc_css_modules/tests/fixture/issues/issuse-7447.css
new file mode 100644
index 0000000000..161004991b
--- /dev/null
+++ b/crates/swc_css_modules/tests/fixture/issues/issuse-7447.css
@@ -0,0 +1,7 @@
+:global(.a):hover {
+  color: blue;
+}
+
+:local(.a).b{
+  color: red;
+}
diff --git a/crates/swc_css_modules/tests/fixture/issues/issuse-7447.transform.json b/crates/swc_css_modules/tests/fixture/issues/issuse-7447.transform.json
new file mode 100644
index 0000000000..1d62625f4f
--- /dev/null
+++ b/crates/swc_css_modules/tests/fixture/issues/issuse-7447.transform.json
@@ -0,0 +1,8 @@
+{
+  "a": [
+    {
+      "type": "local",
+      "name": "__local__a"
+    }
+  ]
+}