Repository: swc-project/swc (rust)

Issue:
Star export is not bundled if top-level await is in the same file
### Describe the bug

When bundling a file where `export * from ...` and top-level await are present, the output code does not include the object that should be exported.

### Input code

```typescript
// --- index.mjs ---
import * as items from "./items.mjs";
console.log(JSON.stringify(items, null, 2));

// --- items.mjs ---
await Promise.resolve(true); // Top-level await
export { default } from "./item0.mjs";
export { default as item1 } from "./item1.mjs";
export { item2 } from "./item2.mjs";
export { item as item3 } from "./item3.mjs";
export * as item4 from "./item4.mjs";
export * from "./item5.mjs"; // This export declaration has the bundle issue

// --- item0.mjs ---
let item0; export default item0 = 0;

// --- item1.mjs ---
let item1; export default item1 = 1;

// --- item2.mjs ---
export const item2 = 2;

// --- item3.mjs ---
export const item = 3;

// --- item4.mjs ---
export const item4 = 4;

// --- item5.mjs ---
export const item5 = 5;
```


### Config

.swcrc:

```json
{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "target": "es2021",
    "parser": {
      "syntax": "ecmascript",
      "dynamicImport": true,
      "exportDefaultFrom": true,
      "exportNamespaceFrom": true,
      "topLevelAwait": true
    }
  },
  "module": {
    "type": "es6"
  }
}
```

spack.config.js:

```cjs
const { config } = require("@swc/core/spack");

module.exports = config({
  entry: {
    index: __dirname + "/index.mjs",
  },
  output: {
    path: __dirname,
    name: "bundled.mjs",
  },
});
```

### Playground link

_No response_

### Expected behavior

The execution results of index.mjs and bundled.mjs should be the same.

```bash
$ node index.mjs
{
  "default": 0,
  "item1": 1,
  "item2": 2,
  "item3": 3,
  "item4": {
    "item4": 4
  },
  "item5": 5
}
```

### Actual behavior

There is a difference between the execution results of index.mjs and bundled.mjs.
`"item5": 5` declared with `export * from "./item5.mjs";` is not included in the result of bundled.mjs.

```bash
$ npx spack
Bundling done: 0s 5.018644ms
Done: 0s 0.263434ms

$ node bundled.mjs
{
  "default": 0,
  "item1": 1,
  "item2": 2,
  "item3": 3,
  "item4": {
    "item4": 4
  }
}
```

### Version

1.2.244

### Additional context


Contents of bundled.mjs:

```mjs
const __default = 0;
const __default1 = 1;
const mod = function() {
    return {
        item4: 4
    };
}();
await Promise.resolve(true);
const mod1 = await async function() {
    return {
        default: __default,
        item1: __default1,
        item2: 2,
        item3: 3,
        item4: mod
    };
}();
console.log(JSON.stringify(mod1, null, 2));
```

If top-level await in items.mjs is removed, the following bundled code is output and the execution result is as expected:

```mjs
const __default = 0;
const __default1 = 1;
const mod = function() {
    return {
        item4: 4
    };
}();
const mod1 = function() {
    return {
        default: __default,
        item1: __default1,
        item2: 2,
        item3: 3,
        item4: mod,
        item5: 5
    };
}();
console.log(JSON.stringify(mod1, null, 2));
```


Pull request description:
fix(bundler): handle star export with top-level await
**Description:**
Even in modules where top-level await is present, values exported by `export * from ...` declaration should be bundled as expected.

**BREAKING CHANGE:**

**Related issue (if exists):**
- fix #5642

Patch:
diff --git a/crates/swc_bundler/src/bundler/chunk/merge.rs b/crates/swc_bundler/src/bundler/chunk/merge.rs
index 191e7e3d3b..119243f737 100644
--- a/crates/swc_bundler/src/bundler/chunk/merge.rs
+++ b/crates/swc_bundler/src/bundler/chunk/merge.rs
@@ -370,6 +370,13 @@ where
                                 Callee::Super(_) | Callee::Import(_) => continue,
                                 Callee::Expr(v) => v,
                             },
+                            Expr::Await(AwaitExpr { arg, .. }) => match &mut **arg {
+                                Expr::Call(CallExpr { callee, .. }) => match callee {
+                                    Callee::Super(_) | Callee::Import(_) => continue,
+                                    Callee::Expr(v) => v,
+                                },
+                                _ => continue,
+                            },
                             _ => continue,
                         },
                         None => continue,


Test patch:
diff --git a/crates/swc_bundler/tests/fixture/issue-5642/input/deps.ts b/crates/swc_bundler/tests/fixture/issue-5642/input/deps.ts
new file mode 100644
index 0000000000..012802a17a
--- /dev/null
+++ b/crates/swc_bundler/tests/fixture/issue-5642/input/deps.ts
@@ -0,0 +1,2 @@
+await Promise.resolve(true);
+export * from "./lib1";
diff --git a/crates/swc_bundler/tests/fixture/issue-5642/input/entry.ts b/crates/swc_bundler/tests/fixture/issue-5642/input/entry.ts
new file mode 100644
index 0000000000..f1ff972ff4
--- /dev/null
+++ b/crates/swc_bundler/tests/fixture/issue-5642/input/entry.ts
@@ -0,0 +1,2 @@
+import * as lib from "./deps";
+console.log(lib);
diff --git a/crates/swc_bundler/tests/fixture/issue-5642/input/lib1.ts b/crates/swc_bundler/tests/fixture/issue-5642/input/lib1.ts
new file mode 100644
index 0000000000..f57da3afdf
--- /dev/null
+++ b/crates/swc_bundler/tests/fixture/issue-5642/input/lib1.ts
@@ -0,0 +1,1 @@
+export const starExport = 1;
diff --git a/crates/swc_bundler/tests/fixture/issue-5642/output/entry.inlined.ts b/crates/swc_bundler/tests/fixture/issue-5642/output/entry.inlined.ts
new file mode 100644
index 0000000000..be66cea0ec
--- /dev/null
+++ b/crates/swc_bundler/tests/fixture/issue-5642/output/entry.inlined.ts
@@ -0,0 +1,7 @@
+await Promise.resolve(true);
+const mod = await async function() {
+    return {
+        starExport: 1
+    };
+}();
+console.log(mod);
diff --git a/crates/swc_bundler/tests/fixture/issue-5642/output/entry.ts b/crates/swc_bundler/tests/fixture/issue-5642/output/entry.ts
new file mode 100644
index 0000000000..5e62b7be87
--- /dev/null
+++ b/crates/swc_bundler/tests/fixture/issue-5642/output/entry.ts
@@ -0,0 +1,8 @@
+const starExport = 1;
+await Promise.resolve(true);
+const mod = await async function() {
+    return {
+        starExport
+    };
+}();
+console.log(mod);