Repository: swc-project/swc (rust)

Issue:
minifier: calling class without `new` in code can get a parse error code
### Describe the bug

Minifier can reduce the class and adjacent call expression like the function → IIFE form does, but this will cause parse error currently.

### Input code

```typescript
"use strict";
const k = (() => {
    function f() {
        class x {}
        x();
    }
    return f;
})();
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2022",
    "loose": false,
    "minify": {
      "compress": {
        "arguments": false,
        "arrows": true,
        "booleans": true,
        "booleans_as_integers": false,
        "collapse_vars": true,
        "comparisons": true,
        "computed_props": true,
        "conditionals": true,
        "dead_code": true,
        "directives": true,
        "drop_console": false,
        "drop_debugger": true,
        "evaluate": true,
        "expression": false,
        "hoist_funs": false,
        "hoist_props": true,
        "hoist_vars": false,
        "if_return": true,
        "join_vars": true,
        "keep_classnames": false,
        "keep_fargs": true,
        "keep_fnames": false,
        "keep_infinity": false,
        "loops": true,
        "negate_iife": true,
        "properties": true,
        "reduce_funcs": false,
        "reduce_vars": false,
        "side_effects": true,
        "switches": true,
        "typeofs": true,
        "unsafe": false,
        "unsafe_arrows": false,
        "unsafe_comps": false,
        "unsafe_Function": false,
        "unsafe_math": false,
        "unsafe_symbols": false,
        "unsafe_methods": false,
        "unsafe_proto": false,
        "unsafe_regexp": false,
        "unsafe_undefined": false,
        "unused": true,
        "const_to_let": true,
        "pristine_globals": true
      },
      "mangle": false
    }
  },
  "module": {
    "type": "commonjs"
  },
  "minify": false,
  "isModule": false
}
```


### Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.5.2&code=H4sIAAAAAAAAAz3LQQrAIBADwLuvCJ70DWL%2FUkRBWhTcFQTx791WaG6ZEN0pgrjlwNqpUAsxLngYY%2BEPTAVJ6iVwrgVJdNObcJ9EGJjrp2Gs%2B8qmFrk3uTm1rCwPSnZCMW0AAAA%3D&config=H4sIAAAAAAAAA32UO5LbMAyG%2Bz2FR3WKjMscIF3OwKFJUKZDEhoC9Fqz47sHeviRNeROwocfIAEQXx%2B7XXci1%2F3afcmn%2FAy2EtT7v1hoLGwvYunAZUuuxoG7Hzd6ogkFmwhm03UhHdvaA88q2v%2Fc71dFlxAJborVlmOJYXzO6TAPFYiebGKVkC1DYfpfv7KKnxPg2p7tB8QEtrwhxpKJhaGHqgV2mJIdCMzZViXKdFJbI6GWYoKNwZuh4qDy4iNHLJLzlXqw3jj0oKBYwXE8gyaTXCIrJNdT7jNjD4fW93Ofv6nhbFOzrOSEy9wSOa0S9YiR2IRWtBIucKMGC1yL%2B10Zg6nArZZX3Qlj2ejJXwCpQLJExWbQ4s4eQeZpSx3eKmMJMrI8KlzmW7tlgV6KamIMSmWnykDlqHWzgm8Opso67Tgr3igfRQ8GQpBZUULTZ2R31JLyOAAGBUh%2FbdCmagHm%2Fgo3%2BPQg3uDfckvWB2z1yJaP25TGfMD0JkEGPqJ%2F4yCtYNzGVbbEZdjmrXiQ0QCvujSawesSkAfAaNK8L19mQ56HRDR9wsNjTawO1%2Fsezrb0j%2Fe%2BrOKP1aHL6NsM1yU%2F9XdazdKOjOVE3cPztorvp%2B8i%2FbnJl9jXf3MIldo2BgAA

### SWC Info output

_No response_

### Expected behavior

Calling the function (referenced by `k`) will result in runtime TypeError

### Actual behavior

Parse error due to the IIFE form of class declaration.

### Version

1.5.2

### Additional context

I'm not sure if this case can be labelled as a bug, but I'm reporting this.

_No response_

Pull request:
fix(es/fixer): Wrap class expressions in callee


**Related issue:**

 - Closes #8920

Patch:
diff --git a/crates/swc_ecma_transforms_base/src/fixer.rs b/crates/swc_ecma_transforms_base/src/fixer.rs
index 91175d5cbc..a01891f854 100644
--- a/crates/swc_ecma_transforms_base/src/fixer.rs
+++ b/crates/swc_ecma_transforms_base/src/fixer.rs
@@ -87,6 +87,7 @@ impl Fixer<'_> {
         match e {
             Expr::Lit(Lit::Num(..) | Lit::Str(..)) => (),
             Expr::Cond(..)
+            | Expr::Class(..)
             | Expr::Bin(..)
             | Expr::Lit(..)
             | Expr::Unary(..)


Test patch:
diff --git a/crates/swc/tests/fixture/issues-8xxx/8920/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8920/input/.swcrc
new file mode 100644
index 0000000000..2c29c98646
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8920/input/.swcrc
@@ -0,0 +1,64 @@
+{
+    "jsc": {
+        "parser": {
+            "syntax": "ecmascript",
+            "jsx": false
+        },
+        "target": "es2022",
+        "loose": false,
+        "minify": {
+            "compress": {
+                "arguments": false,
+                "arrows": true,
+                "booleans": true,
+                "booleans_as_integers": false,
+                "collapse_vars": true,
+                "comparisons": true,
+                "computed_props": true,
+                "conditionals": true,
+                "dead_code": true,
+                "directives": true,
+                "drop_console": false,
+                "drop_debugger": true,
+                "evaluate": true,
+                "expression": false,
+                "hoist_funs": false,
+                "hoist_props": true,
+                "hoist_vars": false,
+                "if_return": true,
+                "join_vars": true,
+                "keep_classnames": false,
+                "keep_fargs": true,
+                "keep_fnames": false,
+                "keep_infinity": false,
+                "loops": true,
+                "negate_iife": true,
+                "properties": true,
+                "reduce_funcs": false,
+                "reduce_vars": false,
+                "side_effects": true,
+                "switches": true,
+                "typeofs": true,
+                "unsafe": false,
+                "unsafe_arrows": false,
+                "unsafe_comps": false,
+                "unsafe_Function": false,
+                "unsafe_math": false,
+                "unsafe_symbols": false,
+                "unsafe_methods": false,
+                "unsafe_proto": false,
+                "unsafe_regexp": false,
+                "unsafe_undefined": false,
+                "unused": true,
+                "const_to_let": true,
+                "pristine_globals": true
+            },
+            "mangle": false
+        }
+    },
+    "module": {
+        "type": "commonjs"
+    },
+    "minify": false,
+    "isModule": false
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-8xxx/8920/input/1.js b/crates/swc/tests/fixture/issues-8xxx/8920/input/1.js
new file mode 100644
index 0000000000..559d08bc2d
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8920/input/1.js
@@ -0,0 +1,8 @@
+"use strict";
+const k = (() => {
+    function f() {
+        class x { }
+        x();
+    }
+    return f;
+})();
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-8xxx/8920/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8920/output/1.js
new file mode 100644
index 0000000000..4830933f74
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8920/output/1.js
@@ -0,0 +1,5 @@
+"use strict";
+let k = function() {
+    (class {
+    })();
+};