Repository: swc-project/swc (rust)

Issue:
Multiline comment in return statement is compiled incorrectly
### Describe the bug

Repository: https://github.com/srmagura/swc-return-repro

This code: 

```ts
function test() {
  return (
    /* my multiline
           comment */
    0
  );
}
```

results in the output:

```js
function test() {
    return /* my multiline
           comment */ 0;
}
```

The original code returns 0, but the compiled code returns `undefined`.

### Input code

```typescript
function test() {
  return (
    /* my multiline
           comment */
    0
  );
}
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript"
    },
    "target": "es2021"
  },
  "module": {
    "type": "es6"
  }
}
```


### Playground link

https://play.swc.rs/?version=1.2.158&code=H4sIAAAAAAAAA0srzUsuyczPUyhJLS7R0FSo5uVSUChKLSktylPQALEVFPS1FHIrFXJLc0oyczLzUiGCUJCcn5ubmleioKUPETYAUZrWvFy1AAmynk9ZAAAA&config=H4sIAAAAAAAAA6tWyipOVrKqVipILCpOLQKxiivzShIrlKyUSioLUouTizILSpRqdZRKEovSU0uAwqnFRgZGhiCh3PyU0pxUkB6QUrCUmVJtLQCwc2SyVAAAAA%3D%3D

### Expected behavior

The compiled code should retain the parentheses around the `return` statement value, to match the original source code.

### Actual behavior

The compiled code does not have the parenthesis, resulting in a function that returns `undefined`.

### Version

1.2.159

### Additional context

_No response_

Pull request:
fix(es/codegen): multiline comments in return stmt
<!-- 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 #4098 

Patch:
diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs
index b7c04bd558..0cbbd3f388 100644
--- a/crates/swc_ecma_codegen/src/lib.rs
+++ b/crates/swc_ecma_codegen/src/lib.rs
@@ -2538,7 +2538,14 @@ where
 
             // see #415
             if let Some(cmt) = cmt.get_leading(lo) {
-                if cmt.iter().any(|cmt| cmt.kind == CommentKind::Line) {
+                if cmt.iter().any(|cmt| {
+                    cmt.kind == CommentKind::Line
+                        || cmt
+                            .text
+                            .chars()
+                            // https://tc39.es/ecma262/#table-line-terminator-code-points
+                            .any(|c| c == '\n' || c == '\r' || c == '\u{2028}' || c == '\u{2029}')
+                }) {
                     return true;
                 }
             }


Test patch:
diff --git a/crates/swc/tests/fixture/issue-4098/input/index.js b/crates/swc/tests/fixture/issue-4098/input/index.js
new file mode 100644
index 0000000000..d901893c45
--- /dev/null
+++ b/crates/swc/tests/fixture/issue-4098/input/index.js
@@ -0,0 +1,7 @@
+function test() {
+    return (
+        /* my multiline
+             comment */
+        0
+    );
+}
diff --git a/crates/swc/tests/fixture/issue-4098/output/index.js b/crates/swc/tests/fixture/issue-4098/output/index.js
new file mode 100644
index 0000000000..c6b8c2a3c4
--- /dev/null
+++ b/crates/swc/tests/fixture/issue-4098/output/index.js
@@ -0,0 +1,4 @@
+function test() {
+    return(/* my multiline
+             comment */ 0);
+}