Repository: swc-project/swc (rust)

Issue:
[css/modules] composes fails when using multiple selectors
### Describe the bug

`composes` does not work if you use multiple class selectors in the declaration that defines `composes`

### Input code

```typescript
.root-class {
    background-color: red;
}

.chain-1,
.chain-2 {
    composes: root-class;
}

.chain-1 {
    color: blue;
}

.chain-2 {
    color: green;
}
```


### Config

_No response_

### Playground link

_No response_

### SWC Info output

_No response_

### Expected behavior

```json
{
  "root-class": [
    {
      "type": "local",
      "name": "__local__root-class"
    }
  ],
  "chain-1": [
    {
      "type": "local",
      "name": "__local__chain-1"
    },
    {
      "type": "local",
      "name": "__local__root-class"
    }
  ],
  "chain-2": [
    {
      "type": "local",
      "name": "__local__chain-2"
    },
    {
      "type": "local",
      "name": "__local__root-class"
    }
  ]
}
```

### Actual behavior

```json
{
  "root-class": [
    {
      "type": "local",
      "name": "__local__root-class"
    }
  ],
  "chain-1": [
    {
      "type": "local",
      "name": "__local__chain-1"
    },
  ],
  "chain-2": [
    {
      "type": "local",
      "name": "__local__chain-2"
    },
  ]
}
```

### Version

main

### Additional context

_No response_

Pull request description:
fix(css/modules): Support composes when using multiple subclass selectors
Resolves #7948 

Patch:
diff --git a/crates/swc_css_modules/src/lib.rs b/crates/swc_css_modules/src/lib.rs
index cf84afd841..49678021c4 100644
--- a/crates/swc_css_modules/src/lib.rs
+++ b/crates/swc_css_modules/src/lib.rs
@@ -204,13 +204,13 @@ where
         n.visit_mut_children_with(self);
 
         if let QualifiedRulePrelude::SelectorList(sel) = &n.prelude {
-            //
-            if sel.children.len() == 1 && sel.children[0].children.len() == 1 {
-                if let ComplexSelectorChildren::CompoundSelector(sel) = &sel.children[0].children[0]
-                {
-                    if sel.subclass_selectors.len() == 1 {
-                        if let SubclassSelector::Class(class_sel) = &sel.subclass_selectors[0] {
-                            if let Some(composes) = self.data.composes_for_current.take() {
+            let composes = self.data.composes_for_current.take();
+
+            for child in &sel.children {
+                if let ComplexSelectorChildren::CompoundSelector(sel) = &child.children[0] {
+                    for subclass_sel in &sel.subclass_selectors {
+                        if let SubclassSelector::Class(class_sel) = &subclass_sel {
+                            if let Some(composes) = &composes {
                                 let key = self
                                     .data
                                     .renamed_to_orig


Test patch:
diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-7948/issue-7948.compiled.css b/crates/swc_css_modules/tests/fixture/modules/issue-7948/issue-7948.compiled.css
new file mode 100644
index 0000000000..17561d7af9
--- /dev/null
+++ b/crates/swc_css_modules/tests/fixture/modules/issue-7948/issue-7948.compiled.css
@@ -0,0 +1,11 @@
+.__local__root-class {
+  background-color: red;
+}
+.__local__chain-1, 
+.__local__chain-2 {}
+.__local__chain-1 {
+  color: blue;
+}
+.__local__chain-2 {
+  color: green;
+}
diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-7948/issue-7948.css b/crates/swc_css_modules/tests/fixture/modules/issue-7948/issue-7948.css
new file mode 100644
index 0000000000..93a74fda23
--- /dev/null
+++ b/crates/swc_css_modules/tests/fixture/modules/issue-7948/issue-7948.css
@@ -0,0 +1,16 @@
+.root-class {
+    background-color: red;
+}
+
+.chain-1,
+.chain-2 {
+    composes: root-class;
+}
+
+.chain-1 {
+    color: blue;
+}
+
+.chain-2 {
+    color: green;
+}
diff --git a/crates/swc_css_modules/tests/fixture/modules/issue-7948/issue-7948.transform.json b/crates/swc_css_modules/tests/fixture/modules/issue-7948/issue-7948.transform.json
new file mode 100644
index 0000000000..9a965a943e
--- /dev/null
+++ b/crates/swc_css_modules/tests/fixture/modules/issue-7948/issue-7948.transform.json
@@ -0,0 +1,28 @@
+{
+  "root-class": [
+    {
+      "type": "local",
+      "name": "__local__root-class"
+    }
+  ],
+  "chain-1": [
+    {
+      "type": "local",
+      "name": "__local__chain-1"
+    },
+    {
+      "type": "local",
+      "name": "__local__root-class"
+    }
+  ],
+  "chain-2": [
+    {
+      "type": "local",
+      "name": "__local__chain-2"
+    },
+    {
+      "type": "local",
+      "name": "__local__root-class"
+    }
+  ]
+}