Repository: swc-project/swc (rust)

Issue:
optional chaining syntax is not compiled
### Describe the bug
When there are multiple optional chaining syntaxes, some will be compiled successfully, but some will not be compiled.

![image](https://github.com/swc-project/swc/assets/23253540/bd20ca93-85b2-4e02-9372-c9bb066b6a2b)


### Input code

```typescript
const ModalInner = ({ data }: { data: GetReturnOrderDetails.Result }) => {
  return (
    <div className={styles.qcWrapper} ref={wrapperRef} id="qcDataScroll">
      {data!.qcDataList.map(qcData => (
        <div className={styles.desc} key={qcData.flawDesc}>
          <div className={styles.descTitle}>{qcData?.flawDesc}</div>
          {qcData?.flawImageList?.length === 0 ? (
            <Empty />
          ) : (
            <Album
              data={(qcData?.flawImageList || [])?.map(src => ({
                url: src,
                describe: qcData?.flawDesc
              }))}
              showIndicators
              useSafeAreaBottom
              showDescription
              current={current}
            >
              test
            </Album>
          )}
        </div>
      ))}
    </div>
  )
}
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}
```


### Playground link

https://play.swc.rs/?version=1.3.66&code=H4sIAAAAAAAAA31Ry27CMBC85yu2nBKpCj1HOIiKqkLqQ4JKPVQ9GGeBqM4De1OEjP%2B9eVAg7uO23pnZ2R17osg1wWORcDnLc1TAwDeQcOJgI%2BiqCO6R5kiVyp9VgmqKxFOpwznqShLYAFgMxgNQLQf8ugQYJeknCMm1fuIZMqNpL1GHW%2FGqeFmisjV9xcyue81xZSFN2GArprXlQqhCykHcTgIwzRpXYYc9pJrCjJd%2B92zM%2FSPvT9cEtbDwgXtmOlW4knw3bbrxSfuv%2BiUliTY%2Bysdn%2FWhYiy6H9CizjK%2Bx2XgcSszXtAHGGNzA%2BGLn1vkuK2kPw8tBAUQuayKXVdZrQftFzPi%2FusLhAG%2FvwbjNSyvRhmWcAQCVkhHU8PUPpDldpUuMwD3codogsE5Lb4rdLE9SwalQ2gErjQu%2BwolCflsQFe5VjXjampeUFrmDikopzImZY9G3jh02oaZ%2BjsM2yF7Y5xG9H%2F0%2B69QMPOt5X%2B8ckCE4AwAA&config=H4sIAAAAAAAAA1WPSw7CMAxE9z1F5DVbWHAHDhEFtwrKT7ErEVW9O%2FkDu%2FjNTMY%2BFiHgRQru4sjPPAQZCeOcM6HkWL4zAU4BSUUdGC5DZSoSxx0rOZsALOOGXEJI1%2B4G4z1hZqs0hJ1Z7fSafvuUtyEi0b%2BxWKXbzMy3uqVXgvXPvYr9jrJrq7%2FB1zTK5seg6TGS9YjzA2yuiPwTAQAA

### Expected behavior

qcData.flawImageList

### Actual behavior

_No response_

### Version

1.3.66

### Additional context

_No response_

Pull request:
fix(es/compat): Visit transformed expression in optional chaining pass
**Description:**

**Related issue:**

 - Closes #7612.

Patch:
diff --git a/crates/swc_ecma_transforms_compat/src/es2020/optional_chaining.rs b/crates/swc_ecma_transforms_compat/src/es2020/optional_chaining.rs
index 1147075e1b..1ce54d2184 100644
--- a/crates/swc_ecma_transforms_compat/src/es2020/optional_chaining.rs
+++ b/crates/swc_ecma_transforms_compat/src/es2020/optional_chaining.rs
@@ -203,7 +203,10 @@ impl OptChaining {
                 Expr::OptChain(next) => {
                     current = next;
                 }
-                base => return (base, count, chain),
+                mut base => {
+                    base.visit_mut_children_with(self);
+                    return (base, count, chain);
+                }
             }
         }
     }


Test patch:
diff --git a/crates/swc/tests/fixture/issues-7xxx/7612/input/.swcrc b/crates/swc/tests/fixture/issues-7xxx/7612/input/.swcrc
new file mode 100644
index 0000000000..65f433d6c2
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-7xxx/7612/input/.swcrc
@@ -0,0 +1,19 @@
+{
+    "jsc": {
+        "parser": {
+            "syntax": "typescript",
+            "tsx": true
+        },
+        "target": "es5",
+        "loose": false,
+        "minify": {
+            "compress": false,
+            "mangle": false
+        }
+    },
+    "module": {
+        "type": "es6"
+    },
+    "minify": false,
+    "isModule": true
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-7xxx/7612/input/1.js b/crates/swc/tests/fixture/issues-7xxx/7612/input/1.js
new file mode 100644
index 0000000000..2f9b88a649
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-7xxx/7612/input/1.js
@@ -0,0 +1,1 @@
+(qcData?.flawImageList || [])?.map()
diff --git a/crates/swc/tests/fixture/issues-7xxx/7612/output/1.js b/crates/swc/tests/fixture/issues-7xxx/7612/output/1.js
new file mode 100644
index 0000000000..9bd98b4b82
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-7xxx/7612/output/1.js
@@ -0,0 +1,2 @@
+var _this, _qcData;
+(_this = ((_qcData = qcData) === null || _qcData === void 0 ? void 0 : _qcData.flawImageList) || []) === null || _this === void 0 ? void 0 : _this.map();
diff --git a/crates/swc/tests/tsc-references/deleteChain.1.normal.js b/crates/swc/tests/tsc-references/deleteChain.1.normal.js
index 18dbe291fe..790f9fee63 100644
--- a/crates/swc/tests/tsc-references/deleteChain.1.normal.js
+++ b/crates/swc/tests/tsc-references/deleteChain.1.normal.js
@@ -1,5 +1,5 @@
 //// [deleteChain.ts]
-var _o1, _o11, _o2, _o21, _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _this, _o4_b_c_d1, _o4_b1, _o5_b_c_d, _o5_b, _o5, _o5_b_c_d1, _o5_b1, _o51, _o6_b_c_d, _o6_b, _o6_b_c_d1, _o6_b1;
+var _o1, _o11, _o2, _o21, _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _this, _o4_b1, _o4_b_c_d1, _o4_b2, _o5_b_c_d, _o5_b, _o5, _o5_b_c_d1, _o5_b1, _o51, _o6_b_c_d, _o6_b, _o6_b_c_d1, _o6_b1;
 (_o1 = o1) === null || _o1 === void 0 ? true : delete _o1.b;
 delete ((_o11 = o1) === null || _o11 === void 0 ? void 0 : _o11.b);
 (_o2 = o2) === null || _o2 === void 0 ? true : delete _o2.b.c;
@@ -7,8 +7,8 @@ delete ((_o21 = o2) === null || _o21 === void 0 ? void 0 : _o21.b.c);
 (_o3_b = o3.b) === null || _o3_b === void 0 ? true : delete _o3_b.c;
 delete ((_o3_b1 = o3.b) === null || _o3_b1 === void 0 ? void 0 : _o3_b1.c);
 (_o4_b = o4.b) === null || _o4_b === void 0 ? true : (_o4_b_c_d = _o4_b.c.d) === null || _o4_b_c_d === void 0 ? true : delete _o4_b_c_d.e;
-(_this = (o4.b?.c.d)) === null || _this === void 0 ? true : delete _this.e;
-delete ((_o4_b1 = o4.b) === null || _o4_b1 === void 0 ? void 0 : (_o4_b_c_d1 = _o4_b1.c.d) === null || _o4_b_c_d1 === void 0 ? void 0 : _o4_b_c_d1.e);
+(_this = (_o4_b1 = o4.b) === null || _o4_b1 === void 0 ? void 0 : _o4_b1.c.d) === null || _this === void 0 ? true : delete _this.e;
+delete ((_o4_b2 = o4.b) === null || _o4_b2 === void 0 ? void 0 : (_o4_b_c_d1 = _o4_b2.c.d) === null || _o4_b_c_d1 === void 0 ? void 0 : _o4_b_c_d1.e);
 (_o5_b = (_o5 = o5).b) === null || _o5_b === void 0 ? true : (_o5_b_c_d = _o5_b.call(_o5).c.d) === null || _o5_b_c_d === void 0 ? true : delete _o5_b_c_d.e;
 delete ((_o5_b1 = (_o51 = o5).b) === null || _o5_b1 === void 0 ? void 0 : (_o5_b_c_d1 = _o5_b1.call(_o51).c.d) === null || _o5_b_c_d1 === void 0 ? void 0 : _o5_b_c_d1.e);
 (_o6_b = o6.b) === null || _o6_b === void 0 ? true : (_o6_b_c_d = _o6_b["c"].d) === null || _o6_b_c_d === void 0 ? true : delete _o6_b_c_d["e"];
diff --git a/crates/swc/tests/tsc-references/deleteChain.2.minified.js b/crates/swc/tests/tsc-references/deleteChain.2.minified.js
index 61142f8276..b55a36419f 100644
--- a/crates/swc/tests/tsc-references/deleteChain.2.minified.js
+++ b/crates/swc/tests/tsc-references/deleteChain.2.minified.js
@@ -1,3 +1,3 @@
 //// [deleteChain.ts]
-var _o1, _o11, _o2, _o21, _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _this, _o4_b_c_d1, _o4_b1, _o5_b_c_d, _o5_b, _o5, _o5_b_c_d1, _o5_b1, _o51, _o6_b_c_d, _o6_b, _o6_b_c_d1, _o6_b1;
-null === (_o1 = o1) || void 0 === _o1 || delete _o1.b, delete (null === (_o11 = o1) || void 0 === _o11 ? void 0 : _o11.b), null === (_o2 = o2) || void 0 === _o2 || delete _o2.b.c, delete (null === (_o21 = o2) || void 0 === _o21 ? void 0 : _o21.b.c), null === (_o3_b = o3.b) || void 0 === _o3_b || delete _o3_b.c, delete (null === (_o3_b1 = o3.b) || void 0 === _o3_b1 ? void 0 : _o3_b1.c), null === (_o4_b = o4.b) || void 0 === _o4_b || null === (_o4_b_c_d = _o4_b.c.d) || void 0 === _o4_b_c_d || delete _o4_b_c_d.e, null === (_this = o4.b?.c.d) || void 0 === _this || delete _this.e, delete (null === (_o4_b1 = o4.b) || void 0 === _o4_b1 ? void 0 : null === (_o4_b_c_d1 = _o4_b1.c.d) || void 0 === _o4_b_c_d1 ? void 0 : _o4_b_c_d1.e), null === (_o5_b = (_o5 = o5).b) || void 0 === _o5_b || null === (_o5_b_c_d = _o5_b.call(_o5).c.d) || void 0 === _o5_b_c_d || delete _o5_b_c_d.e, delete (null === (_o5_b1 = (_o51 = o5).b) || void 0 === _o5_b1 ? void 0 : null === (_o5_b_c_d1 = _o5_b1.call(_o51).c.d) || void 0 === _o5_b_c_d1 ? void 0 : _o5_b_c_d1.e), null === (_o6_b = o6.b) || void 0 === _o6_b || null === (_o6_b_c_d = _o6_b.c.d) || void 0 === _o6_b_c_d || delete _o6_b_c_d.e, delete (null === (_o6_b1 = o6.b) || void 0 === _o6_b1 ? void 0 : null === (_o6_b_c_d1 = _o6_b1.c.d) || void 0 === _o6_b_c_d1 ? void 0 : _o6_b_c_d1.e);
+var _o1, _o11, _o2, _o21, _o3_b, _o3_b1, _o4_b_c_d, _o4_b, _this, _o4_b1, _o4_b_c_d1, _o4_b2, _o5_b_c_d, _o5_b, _o5, _o5_b_c_d1, _o5_b1, _o51, _o6_b_c_d, _o6_b, _o6_b_c_d1, _o6_b1;
+null === (_o1 = o1) || void 0 === _o1 || delete _o1.b, delete (null === (_o11 = o1) || void 0 === _o11 ? void 0 : _o11.b), null === (_o2 = o2) || void 0 === _o2 || delete _o2.b.c, delete (null === (_o21 = o2) || void 0 === _o21 ? void 0 : _o21.b.c), null === (_o3_b = o3.b) || void 0 === _o3_b || delete _o3_b.c, delete (null === (_o3_b1 = o3.b) || void 0 === _o3_b1 ? void 0 : _o3_b1.c), null === (_o4_b = o4.b) || void 0 === _o4_b || null === (_o4_b_c_d = _o4_b.c.d) || void 0 === _o4_b_c_d || delete _o4_b_c_d.e, null === (_this = null === (_o4_b1 = o4.b) || void 0 === _o4_b1 ? void 0 : _o4_b1.c.d) || void 0 === _this || delete _this.e, delete (null === (_o4_b2 = o4.b) || void 0 === _o4_b2 ? void 0 : null === (_o4_b_c_d1 = _o4_b2.c.d) || void 0 === _o4_b_c_d1 ? void 0 : _o4_b_c_d1.e), null === (_o5_b = (_o5 = o5).b) || void 0 === _o5_b || null === (_o5_b_c_d = _o5_b.call(_o5).c.d) || void 0 === _o5_b_c_d || delete _o5_b_c_d.e, delete (null === (_o5_b1 = (_o51 = o5).b) || void 0 === _o5_b1 ? void 0 : null === (_o5_b_c_d1 = _o5_b1.call(_o51).c.d) || void 0 === _o5_b_c_d1 ? void 0 : _o5_b_c_d1.e), null === (_o6_b = o6.b) || void 0 === _o6_b || null === (_o6_b_c_d = _o6_b.c.d) || void 0 === _o6_b_c_d || delete _o6_b_c_d.e, delete (null === (_o6_b1 = o6.b) || void 0 === _o6_b1 ? void 0 : null === (_o6_b_c_d1 = _o6_b1.c.d) || void 0 === _o6_b_c_d1 ? void 0 : _o6_b_c_d1.e);
diff --git a/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-member-access/output.js b/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-member-access/output.js
index 0c80837a83..a819073743 100644
--- a/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-member-access/output.js
+++ b/crates/swc_ecma_transforms_compat/tests/optional-chaining/general-member-access/output.js
@@ -1,4 +1,4 @@
-var _foo, _a_b_c, _a, _a_b_c_d, _a_b, _a_b_c_d1, _a_b_c1, _orders, _orders_, _orders1, _client, _orders_client_key, _a1, _c;
+var _foo, _a_b_c, _a, _a_b_c_d, _a_b, _a_b_c_d1, _a_b_c1, _orders, _orders_, _orders1, _client, _orders_client_key, _a1, _c, _a2;
 (_foo = foo) === null || _foo === void 0 ? void 0 : _foo.bar;
 (_a = a) === null || _a === void 0 ? void 0 : (_a_b_c = _a.b.c) === null || _a_b_c === void 0 ? void 0 : _a_b_c.d.e;
 (_a_b = a.b) === null || _a_b === void 0 ? void 0 : (_a_b_c_d = _a_b.c.d) === null || _a_b_c_d === void 0 ? void 0 : _a_b_c_d.e;
@@ -8,4 +8,4 @@ var _foo, _a_b_c, _a, _a_b_c_d, _a_b, _a_b_c_d1, _a_b_c1, _orders, _orders_, _or
 orders[(_client = client) === null || _client === void 0 ? void 0 : _client.key].price;
 (_orders_client_key = orders[client.key]) === null || _orders_client_key === void 0 ? void 0 : _orders_client_key.price;
 (0, (_a1 = a) === null || _a1 === void 0 ? void 0 : _a1.b).c;
-(0, (_c = (0, a?.b).c) === null || _c === void 0 ? void 0 : _c.d).e;
+(0, (_c = (0, (_a2 = a) === null || _a2 === void 0 ? void 0 : _a2.b).c) === null || _c === void 0 ? void 0 : _c.d).e;