Repository: swc-project/swc (rust)

Issue:
Correctness - Division plus block comment is turned into line comment
### Describe the bug

When a division operator is followed by a block comment, the result must have a whitespace between them, otherwise it becomes a line comment. 

```js
// original
a / /**/ b
// current behavior
a//**/b
// what it should look like
a/ /**/b
```

### Input code

```typescript
console.log(1 / /* @__PURE__ */something())
```


### Config

```json
{
  "jsc": {
    "externalHelpers": true,
    "parser": {
      "tsx": false,
      "syntax": "typescript",
    },
    "preserveAllComments": true,
    "target": "es5"
  },
  "minify": true,
}
```


### Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.28&code=H4sIAAAAAAAAA0vOzyvOz0nVy8lP1zBU0FfQ11JwiI8PCA1yjY9X0NIvzs9NLcnIzEvX0NQEAG54Sh4rAAAA&config=H4sIAAAAAAAAA12NPQ7CMAyF954i8tyVhQ2x9BpR9YqCnBDZBjWqendctXRg8%2Fvx95YuBHrqSNew%2BOkCs0FK5AFcIeqByRv9HtYoCjnL7pjOLqfIenTc01YsbjZZq9BRUjXa0%2FUHEjjogxvz%2FZUziv0tWZQHbGNAL9Qdn5RTSVM7q%2BsXeXWPCsAAAAA%3D

### SWC Info output

_No response_

### Expected behavior

The output should be this:
```js
console.log(1/ /* @__PURE__ */something())
```

### Actual behavior

The output is this:

```js
console.log(1//* @__PURE__ */something());
```

### Version

1.7.28

### Additional context

This just broke my builds very unexpectedly.

Pull request:
fix(es/codegen): Emit space after div if rhs has leading comment
<!-- Note: CI script will automatically rebase your PR so please do not rebase unless required -->

<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. -->

**Description:**

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

**BREAKING CHANGE:**

<!--
If this PR introduces a breaking change, it must contain a notice for it to be included in the CHANGELOG. Add description or remove entirely if not breaking.

You may need to update `MIGRATION.md` for the breaking changes.
-->

**Related issue (if exists):**
Closes #9630 

Patch:
diff --git a/.changeset/neat-ties-smoke.md b/.changeset/neat-ties-smoke.md
new file mode 100644
index 0000000000..c15ac66454
--- /dev/null
+++ b/.changeset/neat-ties-smoke.md
@@ -0,0 +1,6 @@
+---
+swc_ecma_codegen: patch
+swc_core: patch
+---
+
+fix(es/codegen): Emit space after div if rhs has leading comment
diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs
index aa5593bac6..8939e3e96a 100644
--- a/crates/swc_ecma_codegen/src/lib.rs
+++ b/crates/swc_ecma_codegen/src/lib.rs
@@ -1267,6 +1267,13 @@ where
         let need_post_space = if self.cfg.minify {
             if is_kwd_op {
                 node.right.starts_with_alpha_num()
+            } else if node.op == op!("/") {
+                let span = node.right.span();
+
+                span.is_pure()
+                    || self
+                        .comments
+                        .map_or(false, |comments| comments.has_leading(node.right.span().lo))
             } else {
                 require_space_before_rhs(&node.right, &node.op)
             }


Test patch:
diff --git a/crates/swc_ecma_codegen/src/tests.rs b/crates/swc_ecma_codegen/src/tests.rs
index 416a4732cb..dbe40ebda2 100644
--- a/crates/swc_ecma_codegen/src/tests.rs
+++ b/crates/swc_ecma_codegen/src/tests.rs
@@ -962,6 +962,19 @@ fn issue_8491_2() {
     );
 }
 
+#[test]
+fn issue_9630() {
+    test_from_to_custom_config(
+        "console.log(1 / /* @__PURE__ */ something())",
+        "console.log(1/ /* @__PURE__ */something())",
+        Config {
+            minify: true,
+            ..Default::default()
+        },
+        Default::default(),
+    );
+}
+
 #[testing::fixture("tests/str-lits/**/*.txt")]
 fn test_str_lit(input: PathBuf) {
     test_str_lit_inner(input)