Repository: swc-project/swc (rust)

Issue:
minifier: invalid handling of exponentiate with `NaN` exponent
### Describe the bug

I thought that #8924 occurs only in `undefined` exponent, however same result happens with `NaN` exponent.

### Input code

```typescript
"use strict";
const k = (() => {
  let x = 1;
  x **= undefined / x;
  return x;
})();
```


### 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": {
        "toplevel": false,
        "keep_classnames": false,
        "keep_fnames": false,
        "keep_private_props": false,
        "ie8": false,
        "safari10": false
      }
    }
  },
  "module": {
    "type": "commonjs"
  },
  "minify": false,
  "isModule": false
}
```


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

https://play.swc.rs/?version=1.5.5&code=H4sIAAAAAAAAAxXIQQqAIBBG4b2n%2BHE1uonWYpfRCaSYQEcQorunu%2Fc%2B2xujaS1JbTDpkaa4EEHkEA%2B8BrhZMSbtYc6A9xFdMp9FOGPDWFxZe5XVnyMXfkvq7g1WAAAA&config=H4sIAAAAAAAAA41VwW7bMAy99ysCn3focir2AbvtGwTFohxlsmiIlJugyL%2BPVuw0bWhjlyDm0yNF8pH6eNntmhO1za%2Fdh%2FyVj8Fmgnz%2FFgtdEtuzWBpoe0ttDgM3Pxb0RBPkbSSopusNadjmDriyaP%2B638%2BMJiISLIzZ1ocU%2FOUxZov9kIHowSZWcVl6SExf%2BTOW8X0COJdH%2BwExgk0biLFkQmLoIGuOW4zRDgRmtFnxMt3U5kCohZjAwuDMkHFQ8eQCB0wS8xl1YJ1p0YEChQwthxE0msQSWiJJT8mnwg4Opetqn7%2BxYbSxWFZiwrm2RG6reD1iIDa%2BJK2EN3ClBjdwLu53ZvAmA5ecnnknDGmlJ38BpALREiXbg%2Ba3nvCipzW232SG5EWyfFFw0beWZYJOimpC8Eplp8pA5qB1M4MrLUyVbbXrzPBK%2BSg4MOC9aEVxTe%2BB26MWlC8DoFcA6a%2F1mqpugLlP4Qo%2BDcQG%2FFuyZF1g84ne8nEdpUt%2FwLgRoAc%2Bots4IK1gXIezbInzsI6X5ECkAU49UqgCz0tABoDRxLovn7Qh4yEeTRfx8Lkm5gPX%2Bx7uberqvD%2FsS8YhwghxTcb%2FMSKbqNxtnFS9TPbT9MKbJkorgxd%2Bvn55NiSVl%2BW3JtX06MpDQlWT03MiEuoxnaj5PLk8H%2FdITaA%2FC%2F0W4%2FoPf3j7aeoGAAA%3D

### SWC Info output

_No response_

### Expected behavior

k should be `NaN`

### Actual behavior

k is 1

### Version

1.5.5

### Additional context

_No response_

Pull request description:
fix(es/minifier): Abort seq inliner on `**`
**Description:**


**Related issue:**

 - Closes #8942

Patch:
diff --git a/crates/swc_ecma_minifier/src/compress/optimize/dead_code.rs b/crates/swc_ecma_minifier/src/compress/optimize/dead_code.rs
index 614a2fc5a4..bbf2bc224b 100644
--- a/crates/swc_ecma_minifier/src/compress/optimize/dead_code.rs
+++ b/crates/swc_ecma_minifier/src/compress/optimize/dead_code.rs
@@ -68,6 +68,10 @@ impl Optimizer<'_> {
         if let Expr::Assign(assign) = e {
             // x += 1 => x + 1
             if let Some(op) = assign.op.to_update() {
+                if op == op!("**") {
+                    return false;
+                }
+
                 if let Some(lhs) = assign.left.as_ident() {
                     //
                     if self
diff --git a/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs b/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs
index 415b21eb98..9ea419d07f 100644
--- a/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs
+++ b/crates/swc_ecma_minifier/src/compress/optimize/sequences.rs
@@ -1562,6 +1562,7 @@ impl Optimizer<'_> {
             | Expr::Tpl(..)
             | Expr::TaggedTpl(..) => return Ok(false),
 
+            // See https://github.com/swc-project/swc/issues/8924 and https://github.com/swc-project/swc/issues/8942
             Expr::Assign(AssignExpr {
                 op: op!("**="),
                 right,
@@ -1572,7 +1573,7 @@ impl Optimizer<'_> {
                 right,
                 ..
             }) => {
-                if is_pure_undefined(&self.expr_ctx, right) {
+                if !right.is_lit() {
                     return Ok(false);
                 }
             }


Test patch:
diff --git a/crates/swc_ecma_minifier/tests/exec.rs b/crates/swc_ecma_minifier/tests/exec.rs
index d3224adc01..ff42d21131 100644
--- a/crates/swc_ecma_minifier/tests/exec.rs
+++ b/crates/swc_ecma_minifier/tests/exec.rs
@@ -11224,6 +11224,21 @@ console.log(eval(foo));",
     );
 }
 
+#[test]
+fn issue_8942() {
+    run_default_exec_test(
+        "
+        'use strict';
+        const k = (() => {
+            let x = 1;
+            x **= undefined / x;
+            return x;
+        })();
+        console.log(k);
+        ",
+    );
+}
+
 #[test]
 fn issue_8937() {
     run_default_exec_test(
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/8924/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/8924/output.js
index f010cc298f..c254dba096 100644
--- a/crates/swc_ecma_minifier/tests/fixture/issues/8924/output.js
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/8924/output.js
@@ -1,2 +1,5 @@
 "use strict";
-const k = NaN;
+const k = (()=>{
+    let x = 1;
+    return x **= void 0;
+})();