Repository: swc-project/swc (rust)

Issue:
Bare "type" used as expression statement without semicolon causes syntax error
### Describe the bug

This is code that appears on DefinitelyTyped; `type` in this context is just an expression statement, not a keyword. Adding a semicolon fixes the problem, though in this case, we are hitting this bug because DT is now formatting with dprint, which can't parse the tree to _add_ the semicolon.

### Input code

```typescript
avplay.setListener({
  onsubtitlechange: (duration, subtitles, type, attributes) => {
      duration // $ExpectType string
      subtitles // $ExpectType string
      type // $ExpectType string
      attributes // $ExpectType AVPlaySubtitleAttribute[]
  }
})
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es2022",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": "unknown"
}
```


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

https://play.swc.rs/?version=1.3.74&code=H4sIAAAAAAAAA0ssK8hJrNQrTi3xySwuSc1LLdKo5uVSUMjPKy5NKsksyUlNzkjMS0%2B1UtBIKS1KLMnMz9NRgEkV6yiUVBak6igklpQUZSaVlqQWayrY2imATQABmBYFfX0FFdeKgtTkkhCgBoVioPK8dJgquHH4lYGswq8C4Qx0dY5hAUBvBkMtcoSpi44Faa3l5arVBAAunNNbCQEAAA%3D%3D&config=H4sIAAAAAAAAA1VPOw7DIAzdOQXy3KFi6NA79BCIOhEtP2GiFkW5eyCBtNns9%2FF7nhnn8CIFdz6XsSxBRsJ47AWh7JL8FgRSDkgq6pDg0tlElRqkIdygZWcgyThiqi4kcRWiOcB4T9gdDbPa6SH%2FZypvQ0Sis7BKpRsNnhNZSwXrn9NGtl9q373BDX6iHnYcBk2P7oTJvZ3%2FOGDLCgEeJWgcAQAA

### SWC Info output

_No response_

### Expected behavior

This code parses; `type` can just be an identifier in an expression statement.

### Actual behavior

Parse error.

### Version

1.3.74

### Additional context

_No response_

Pull request description:
fix(es/parser): Consider ASI while parsing TypeScript type aliases
**Description:**

**Related issue:**

 - Closes #8073.

Patch:
diff --git a/crates/swc_ecma_parser/src/parser/typescript.rs b/crates/swc_ecma_parser/src/parser/typescript.rs
index 44e01d0ecf..1c8e8337da 100644
--- a/crates/swc_ecma_parser/src/parser/typescript.rs
+++ b/crates/swc_ecma_parser/src/parser/typescript.rs
@@ -2581,7 +2581,7 @@ impl<I: Tokens> Parser<I> {
             }
 
             "type" => {
-                if next || is!(self, IdentRef) {
+                if next || (!self.input.had_line_break_before_cur() && is!(self, IdentRef)) {
                     if next {
                         bump!(self);
                     }


Test patch:
diff --git a/crates/swc/tests/fixture/issues-7xxx/7561/es2019/output/1.js b/crates/swc/tests/fixture/issues-7xxx/7561/es2019/output/1.js
index b25065e034..568d4495d9 100644
--- a/crates/swc/tests/fixture/issues-7xxx/7561/es2019/output/1.js
+++ b/crates/swc/tests/fixture/issues-7xxx/7561/es2019/output/1.js
@@ -1,6 +1,6 @@
 var _class_private_field_get = require("@swc/helpers/_/_class_private_field_get");
 var _class_private_field_init = require("@swc/helpers/_/_class_private_field_init");
-var _x = /*#__PURE__*/ new WeakMap();
+var _x = new WeakMap();
 class Foo {
     test() {
         var _this, _this_y;
diff --git a/crates/swc/tests/fixture/issues-7xxx/7561/es2021/output/1.js b/crates/swc/tests/fixture/issues-7xxx/7561/es2021/output/1.js
index b25065e034..568d4495d9 100644
--- a/crates/swc/tests/fixture/issues-7xxx/7561/es2021/output/1.js
+++ b/crates/swc/tests/fixture/issues-7xxx/7561/es2021/output/1.js
@@ -1,6 +1,6 @@
 var _class_private_field_get = require("@swc/helpers/_/_class_private_field_get");
 var _class_private_field_init = require("@swc/helpers/_/_class_private_field_init");
-var _x = /*#__PURE__*/ new WeakMap();
+var _x = new WeakMap();
 class Foo {
     test() {
         var _this, _this_y;
diff --git a/crates/swc/tests/fixture/issues-8xxx/8073/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8073/input/.swcrc
new file mode 100644
index 0000000000..f04f6f5c35
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8073/input/.swcrc
@@ -0,0 +1,19 @@
+{
+    "jsc": {
+        "parser": {
+            "syntax": "typescript",
+            "tsx": false
+        },
+        "target": "es2022",
+        "loose": false,
+        "minify": {
+            "compress": false,
+            "mangle": false
+        }
+    },
+    "module": {
+        "type": "es6"
+    },
+    "minify": false,
+    "isModule": "unknown"
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-8xxx/8073/input/1.js b/crates/swc/tests/fixture/issues-8xxx/8073/input/1.js
new file mode 100644
index 0000000000..00aa1a6d43
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8073/input/1.js
@@ -0,0 +1,8 @@
+avplay.setListener({
+    onsubtitlechange: (duration, subtitles, type, attributes) => {
+        duration // $ExpectType string
+        subtitles // $ExpectType string
+        type // $ExpectType string
+        attributes // $ExpectType AVPlaySubtitleAttribute[]
+    }
+})
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-8xxx/8073/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8073/output/1.js
new file mode 100644
index 0000000000..a0d7d15576
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8073/output/1.js
@@ -0,0 +1,8 @@
+avplay.setListener({
+    onsubtitlechange: (duration, subtitles, type, attributes)=>{
+        duration;
+        subtitles;
+        type;
+        attributes;
+    }
+});
diff --git a/crates/swc/tests/fixture/issues-8xxx/8199/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8199/output/1.js
index ea1836b77e..f366b1b0f4 100644
--- a/crates/swc/tests/fixture/issues-8xxx/8199/output/1.js
+++ b/crates/swc/tests/fixture/issues-8xxx/8199/output/1.js
@@ -1,7 +1,7 @@
 import { jsx as _jsx } from "react/jsx-runtime";
 export const IconSpecHotkey = (param)=>{
     let { icon } = param;
-    return /*#__PURE__*/ _jsx("div", {
+    return _jsx("div", {
         children: icon
     });
 };
diff --git a/crates/swc/tests/fixture/issues-8xxx/8210/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8210/output/1.js
index 7c1f2f74b0..fb9247d0bd 100644
--- a/crates/swc/tests/fixture/issues-8xxx/8210/output/1.js
+++ b/crates/swc/tests/fixture/issues-8xxx/8210/output/1.js
@@ -1,7 +1,7 @@
 import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
 const Component = ()=>{
-    return /*#__PURE__*/ _jsxDEV("p", {
-        thing: /*#__PURE__*/ _jsxDEV("a", {}, void 0, false, {
+    return _jsxDEV("p", {
+        thing: _jsxDEV("a", {}, void 0, false, {
             fileName: "$DIR/tests/fixture/issues-8xxx/8210/input/1.js",
             lineNumber: 2,
             columnNumber: 23
diff --git a/crates/swc_ecma_parser/tests/tsc/asiPreventsParsingAsTypeAlias01.json b/crates/swc_ecma_parser/tests/tsc/asiPreventsParsingAsTypeAlias01.json
index 497fab5d85..ab618fb650 100644
--- a/crates/swc_ecma_parser/tests/tsc/asiPreventsParsingAsTypeAlias01.json
+++ b/crates/swc_ecma_parser/tests/tsc/asiPreventsParsingAsTypeAlias01.json
@@ -106,32 +106,59 @@
       ]
     },
     {
-      "type": "TsTypeAliasDeclaration",
+      "type": "ExpressionStatement",
       "span": {
         "start": 34,
-        "end": 52,
+        "end": 38,
         "ctxt": 0
       },
-      "declare": false,
-      "id": {
+      "expression": {
         "type": "Identifier",
         "span": {
-          "start": 39,
-          "end": 42,
+          "start": 34,
+          "end": 38,
           "ctxt": 0
         },
-        "value": "Foo",
+        "value": "type",
         "optional": false
+      }
+    },
+    {
+      "type": "ExpressionStatement",
+      "span": {
+        "start": 39,
+        "end": 52,
+        "ctxt": 0
       },
-      "typeParams": null,
-      "typeAnnotation": {
-        "type": "TsKeywordType",
+      "expression": {
+        "type": "AssignmentExpression",
         "span": {
-          "start": 45,
+          "start": 39,
           "end": 51,
           "ctxt": 0
         },
-        "kind": "string"
+        "operator": "=",
+        "left": {
+          "type": "Identifier",
+          "span": {
+            "start": 39,
+            "end": 42,
+            "ctxt": 0
+          },
+          "value": "Foo",
+          "optional": false,
+          "typeAnnotation": null
+        },
+        "right": {
+          "type": "Identifier",
+          "span": {
+            "start": 45,
+            "end": 51,
+            "ctxt": 0
+          },
+          "value": "string",
+          "optional": false
+        }
       }
     }
   ],
diff --git a/crates/swc_ecma_parser/tests/tsc/asiPreventsParsingAsTypeAlias02.json b/crates/swc_ecma_parser/tests/tsc/asiPreventsParsingAsTypeAlias02.json
index 76cbc2e2cc..f57e4ce518 100644
--- a/crates/swc_ecma_parser/tests/tsc/asiPreventsParsingAsTypeAlias02.json
+++ b/crates/swc_ecma_parser/tests/tsc/asiPreventsParsingAsTypeAlias02.json
@@ -133,32 +133,59 @@
         },
         "body": [
           {
-            "type": "TsTypeAliasDeclaration",
+            "type": "ExpressionStatement",
             "span": {
               "start": 60,
-              "end": 82,
+              "end": 64,
               "ctxt": 0
             },
-            "declare": false,
-            "id": {
+            "expression": {
               "type": "Identifier",
               "span": {
-                "start": 69,
-                "end": 72,
+                "start": 60,
+                "end": 64,
                 "ctxt": 0
               },
-              "value": "Foo",
+              "value": "type",
               "optional": false
+            }
+          },
+          {
+            "type": "ExpressionStatement",
+            "span": {
+              "start": 69,
+              "end": 82,
+              "ctxt": 0
             },
-            "typeParams": null,
-            "typeAnnotation": {
-              "type": "TsKeywordType",
+            "expression": {
+              "type": "AssignmentExpression",
               "span": {
-                "start": 75,
+                "start": 69,
                 "end": 81,
                 "ctxt": 0
               },
-              "kind": "string"
+              "operator": "=",
+              "left": {
+                "type": "Identifier",
+                "span": {
+                  "start": 69,
+                  "end": 72,
+                  "ctxt": 0
+                },
+                "value": "Foo",
+                "optional": false,
+                "typeAnnotation": null
+              },
+              "right": {
+                "type": "Identifier",
+                "span": {
+                  "start": 75,
+                  "end": 81,
+                  "ctxt": 0
+                },
+                "value": "string",
+                "optional": false
+              }
             }
           }
         ]
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-8073/input.ts b/crates/swc_ecma_parser/tests/typescript/issue-8073/input.ts
new file mode 100644
index 0000000000..00aa1a6d43
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-8073/input.ts
@@ -0,0 +1,8 @@
+avplay.setListener({
+    onsubtitlechange: (duration, subtitles, type, attributes) => {
+        duration // $ExpectType string
+        subtitles // $ExpectType string
+        type // $ExpectType string
+        attributes // $ExpectType AVPlaySubtitleAttribute[]
+    }
+})
\ No newline at end of file
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-8073/input.ts.json b/crates/swc_ecma_parser/tests/typescript/issue-8073/input.ts.json
new file mode 100644
index 0000000000..cb10fc74ae
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-8073/input.ts.json
@@ -0,0 +1,224 @@
+{
+  "type": "Script",
+  "span": {
+    "start": 1,
+    "end": 271,
+    "ctxt": 0
+  },
+  "body": [
+    {
+      "type": "ExpressionStatement",
+      "span": {
+        "start": 1,
+        "end": 271,
+        "ctxt": 0
+      },
+      "expression": {
+        "type": "CallExpression",
+        "span": {
+          "start": 1,
+          "end": 271,
+          "ctxt": 0
+        },
+        "callee": {
+          "type": "MemberExpression",
+          "span": {
+            "start": 1,
+            "end": 19,
+            "ctxt": 0
+          },
+          "object": {
+            "type": "Identifier",
+            "span": {
+              "start": 1,
+              "end": 7,
+              "ctxt": 0
+            },
+            "value": "avplay",
+            "optional": false
+          },
+          "property": {
+            "type": "Identifier",
+            "span": {
+              "start": 8,
+              "end": 19,
+              "ctxt": 0
+            },
+            "value": "setListener",
+            "optional": false
+          }
+        },
+        "arguments": [
+          {
+            "spread": null,
+            "expression": {
+              "type": "ObjectExpression",
+              "span": {
+                "start": 20,
+                "end": 270,
+                "ctxt": 0
+              },
+              "properties": [
+                {
+                  "type": "KeyValueProperty",
+                  "key": {
+                    "type": "Identifier",
+                    "span": {
+                      "start": 26,
+                      "end": 42,
+                      "ctxt": 0
+                    },
+                    "value": "onsubtitlechange",
+                    "optional": false
+                  },
+                  "value": {
+                    "type": "ArrowFunctionExpression",
+                    "span": {
+                      "start": 44,
+                      "end": 268,
+                      "ctxt": 0
+                    },
+                    "params": [
+                      {
+                        "type": "Identifier",
+                        "span": {
+                          "start": 45,
+                          "end": 53,
+                          "ctxt": 0
+                        },
+                        "value": "duration",
+                        "optional": false,
+                        "typeAnnotation": null
+                      },
+                      {
+                        "type": "Identifier",
+                        "span": {
+                          "start": 55,
+                          "end": 64,
+                          "ctxt": 0
+                        },
+                        "value": "subtitles",
+                        "optional": false,
+                        "typeAnnotation": null
+                      },
+                      {
+                        "type": "Identifier",
+                        "span": {
+                          "start": 66,
+                          "end": 70,
+                          "ctxt": 0
+                        },
+                        "value": "type",
+                        "optional": false,
+                        "typeAnnotation": null
+                      },
+                      {
+                        "type": "Identifier",
+                        "span": {
+                          "start": 72,
+                          "end": 82,
+                          "ctxt": 0
+                        },
+                        "value": "attributes",
+                        "optional": false,
+                        "typeAnnotation": null
+                      }
+                    ],
+                    "body": {
+                      "type": "BlockStatement",
+                      "span": {
+                        "start": 87,
+                        "end": 268,
+                        "ctxt": 0
+                      },
+                      "stmts": [
+                        {
+                          "type": "ExpressionStatement",
+                          "span": {
+                            "start": 97,
+                            "end": 105,
+                            "ctxt": 0
+                          },
+                          "expression": {
+                            "type": "Identifier",
+                            "span": {
+                              "start": 97,
+                              "end": 105,
+                              "ctxt": 0
+                            },
+                            "value": "duration",
+                            "optional": false
+                          }
+                        },
+                        {
+                          "type": "ExpressionStatement",
+                          "span": {
+                            "start": 136,
+                            "end": 145,
+                            "ctxt": 0
+                          },
+                          "expression": {
+                            "type": "Identifier",
+                            "span": {
+                              "start": 136,
+                              "end": 145,
+                              "ctxt": 0
+                            },
+                            "value": "subtitles",
+                            "optional": false
+                          }
+                        },
+                        {
+                          "type": "ExpressionStatement",
+                          "span": {
+                            "start": 176,
+                            "end": 180,
+                            "ctxt": 0
+                          },
+                          "expression": {
+                            "type": "Identifier",
+                            "span": {
+                              "start": 176,
+                              "end": 180,
+                              "ctxt": 0
+                            },
+                            "value": "type",
+                            "optional": false
+                          }
+                        },
+                        {
+                          "type": "ExpressionStatement",
+                          "span": {
+                            "start": 211,
+                            "end": 221,
+                            "ctxt": 0
+                          },
+                          "expression": {
+                            "type": "Identifier",
+                            "span": {
+                              "start": 211,
+                              "end": 221,
+                              "ctxt": 0
+                            },
+                            "value": "attributes",
+                            "optional": false
+                          }
+                        }
+                      ]
+                    },
+                    "async": false,
+                    "generator": false,
+                    "typeParameters": null,
+                    "returnType": null
+                  }
+                }
+              ]
+            }
+          }
+        ],
+        "typeArguments": null
+      }
+    }
+  ],
+  "interpreter": null
+}