Repository: swc-project/swc (rust)

Issue:
No diagnostic for missing paren in if statement
### Describe the bug

No diagnostic given for missing paren in if statement header.

### Input code

```typescript
const foo = <T extends {}>() => {
    if (bar() {
        console.log(1);
    }
};
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "target": "es2022",
    "transform": {
      "useDefineForClassFields": true,
      "react": {
        "importSource": "https://esm.sh/preact",
        "runtime": "automatic"
      }
    },
    "loose": false
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}
```


### Playground link

https://play.swc.rs/?version=1.3.41&code=H4sIAAAAAAAAA0vOzysuUUjLz1ewVbAJUUitKEnNSylWqK6109BUsLVTqOblUgCCzDQFjaTEIqAYVAAEkoF683NS9XLy0zUMNa0hErW8XLXWAJRuJZFWAAAA&config=H4sIAAAAAAAAA1WQvW7DMAyE9z6FoTmoCw8ZsrbIlilPQCh0w0J%2FICkgRuB3jyTHcbqJ3%2FF04N0%2Fus78iTWH7l6eZUjAgvyaC5EpKNwKMTolFMuU1OxWVaVKyhkbmRfBKPAvajWhDF%2FDYFbOEGSM7N8TsuAPjhTwGPnbgciR0F3k%2Be8rihGsvvkKIp8i6zlmtljDrqpJDn2P4j%2Fl2qfFstsMnIOSb7uQNXpQsuYpz%2F8ucDFK3RvBSb2tcePjJTvc6qqVLFfuzbZEgcZp9TZEclqdrav5AeQIxLB6AQAA

### Expected behavior

Typescript gives a `')' expected` error.

### Actual behavior

```ts
const foo = ()=>{
    if (bar()) <invalid>;
    {
        console.log(1);
    }
};
```

### Version

1.3.41

### Additional context

_No response_

Pull request description:
fix(es/parser): Use a hard error for missing r-paren in an if 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):**
Fixes #7104 


Patch:
diff --git a/crates/swc_ecma_parser/src/parser/stmt.rs b/crates/swc_ecma_parser/src/parser/stmt.rs
index cc8160ad3d..6e91651288 100644
--- a/crates/swc_ecma_parser/src/parser/stmt.rs
+++ b/crates/swc_ecma_parser/src/parser/stmt.rs
@@ -470,20 +470,8 @@ impl<'a, I: Tokens> Parser<I> {
                     },
                 )
             })?;
-        if !eat!(self, ')') {
-            self.emit_err(self.input.cur_span(), SyntaxError::TS1005);
 
-            let span = span!(self, start);
-            return Ok(IfStmt {
-                span,
-                test,
-                cons: Box::new(Stmt::Expr(ExprStmt {
-                    span,
-                    expr: Box::new(Expr::Invalid(Invalid { span })),
-                })),
-                alt: Default::default(),
-            });
-        }
+        expect!(self, ')');
 
         let cons = {
             // Prevent stack overflow


Test patch:
diff --git a/crates/swc_ecma_parser/tests/typescript-errors/issue-7104/case1/input.ts b/crates/swc_ecma_parser/tests/typescript-errors/issue-7104/case1/input.ts
new file mode 100644
index 0000000000..d9ee8f21f5
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript-errors/issue-7104/case1/input.ts
@@ -0,0 +1,5 @@
+const foo = <T extends {}>() => {
+    if (bar() {
+        console.log(1);
+    }
+};
\ No newline at end of file
diff --git a/crates/swc_ecma_parser/tests/typescript-errors/issue-7104/case1/input.ts.swc-stderr b/crates/swc_ecma_parser/tests/typescript-errors/issue-7104/case1/input.ts.swc-stderr
new file mode 100644
index 0000000000..ed41125e77
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript-errors/issue-7104/case1/input.ts.swc-stderr
@@ -0,0 +1,14 @@
+
+  x An arrow function is not allowed here
+   ,-[$DIR/tests/typescript-errors/issue-7104/case1/input.ts:1:1]
+ 1 | const foo = <T extends {}>() => {
+   :                           ^^
+ 2 |     if (bar() {
+   `----
+
+  x Expression expected
+   ,-[$DIR/tests/typescript-errors/issue-7104/case1/input.ts:1:1]
+ 1 | const foo = <T extends {}>() => {
+   :                          ^
+ 2 |     if (bar() {
+   `----
diff --git a/crates/swc_ecma_parser/tests/typescript-errors/issue-7104/case2/input.ts b/crates/swc_ecma_parser/tests/typescript-errors/issue-7104/case2/input.ts
new file mode 100644
index 0000000000..8d08f4daef
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript-errors/issue-7104/case2/input.ts
@@ -0,0 +1,5 @@
+const foo = () => {
+    if (bar() {
+        console.log(1);
+    }
+};
\ No newline at end of file
diff --git a/crates/swc_ecma_parser/tests/typescript-errors/issue-7104/case2/input.ts.swc-stderr b/crates/swc_ecma_parser/tests/typescript-errors/issue-7104/case2/input.ts.swc-stderr
new file mode 100644
index 0000000000..66bed9cddb
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript-errors/issue-7104/case2/input.ts.swc-stderr
@@ -0,0 +1,8 @@
+
+  x Expected ')', got '{'
+   ,-[$DIR/tests/typescript-errors/issue-7104/case2/input.ts:1:1]
+ 1 | const foo = () => {
+ 2 |     if (bar() {
+   :               ^
+ 3 |         console.log(1);
+   `----