Repository: swc-project/swc (rust)

Issue:
Using compress.evaluate causes error
### Describe the bug

When migrating from Babel and Terser to SWC found that minified code is not working.
Chrome says `Uncaught SyntaxError: Invalid left-hand side expression in prefix operation`
Setting `compress.evaluate` to `false` fixes the problem.

### Input code

```typescript
function c(r,n){const e=new Uint8Array(4*r*r),a=1,o=-.5,s=Math.sqrt(a*a+o*o),c=(r-n)/2;return {e,s,c}}
```


### Config

_No response_

### Playground link

https://play.swc.rs/?version=1.2.208&code=H4sIAAAAAAAAAwXBQQrCQAwF0KvMcmZMWyoKgmThAVx6gBBG7CbBPylFSu%2Fue%2B%2FVNBa3pBlkZVe3HqmxtS29FovbA5BfvlRUFBKeyXkYr9T5KfEZ%2BxeRpcrJqxdSzhisTOc7WqywtDfqpMfxB8loUj9mAAAA&config=H4sIAAAAAAAAA22TzZLbIAzH38XnHLad6R72AXrrMzAKCEdbAx4kkngyefeK2MF20hv68ZfQF7fum233detGyIy5nniKAtfuq0MbgG2mUbqDyhR5GBjvh04g9yhVwj8%2FfvzS6yElxkVw6AJF8lMNZlMYMzLXszqVgFG46SDndFFTclHrmNKAEN9sA2woCvaYV1ebhgFGRnOG3Dzqa5CJU9yhIujMmNO4dY%2BOhFJUs0GH4IxNbi3EUUYrdMaNSOOoKLImt4cOj6XvaxPnp%2FEMQwHBZl8frdBHm98pEYvxJfILWrKdHWc0F7qoyJuMUnJ8ar4TxV0v%2FiJqngMwRwib%2FB%2Fc6yz2Sv8fFUWvg5SpUZ3ymlXEXoszRL5VWLPGLIRNlNEVi7VCuwZf4K4gJocGvdd2N2e%2BkNjTJiuZRky%2B3WvbwK9DmE3zXKo9rXvwBn9rWrKdx8IDyOmV8RSOaXgLEVBOyb1h7YSkV5h1ha%2FjKy3RofYZ3eaicDP1uwWIfVu2ewXJlQpuj448%2FuFnd1%2F%2F3XNJ%2BM8irP26%2FwOhIxN67AMAAA%3D%3D

### Expected behavior

Valid compressed code

### Actual behavior

Invalid compressed code. `Uncaught SyntaxError: Invalid left-hand side expression in prefix operation`

### Version

1.2.208

### Additional context

_No response_

Pull request description:
fix(es/fixer): Handle invalid numeric literals
**Description:**

I'm still investigating.

**Related issue (if exists):**

 - Closes #5112

Patch:
diff --git a/crates/swc_ecma_transforms_base/src/fixer.rs b/crates/swc_ecma_transforms_base/src/fixer.rs
index e3c02fc4ee..33bf65b7a4 100644
--- a/crates/swc_ecma_transforms_base/src/fixer.rs
+++ b/crates/swc_ecma_transforms_base/src/fixer.rs
@@ -648,10 +648,12 @@ impl VisitMut for Fixer<'_> {
                 right,
                 ..
             }) if n.op == op!(unary, "-")
-                && matches!(
-                    (&**left, &**right),
-                    (Expr::Lit(Lit::Num(..)), Expr::Lit(Lit::Num(..)))
-                ) => {}
+                && match (&**left, &**right) {
+                    (Expr::Lit(Lit::Num(l)), Expr::Lit(Lit::Num(..))) => {
+                        !l.value.is_sign_negative()
+                    }
+                    _ => false,
+                } => {}
 
             Expr::Assign(..)
             | Expr::Bin(..)


Test patch:
diff --git a/crates/swc/tests/fixture/issues-5xxx/5112/input/.swcrc b/crates/swc/tests/fixture/issues-5xxx/5112/input/.swcrc
new file mode 100644
index 0000000000..05e11e3459
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-5xxx/5112/input/.swcrc
@@ -0,0 +1,62 @@
+{
+    "jsc": {
+        "parser": {
+            "syntax": "ecmascript",
+            "jsx": false
+        },
+        "target": "es2015",
+        "loose": false,
+        "minify": {
+            "compress": {
+                "arguments": false,
+                "arrows": true,
+                "booleans": true,
+                "booleans_as_integers": false,
+                "collapse_vars": true,
+                "comparisons": true,
+                "computed_props": false,
+                "conditionals": false,
+                "dead_code": false,
+                "directives": false,
+                "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": false,
+                "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": false
+            },
+            "mangle": false
+        }
+    },
+    "module": {
+        "type": "es6"
+    },
+    "minify": false,
+    "isModule": true
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-5xxx/5112/input/index.js b/crates/swc/tests/fixture/issues-5xxx/5112/input/index.js
new file mode 100644
index 0000000000..3d9e7cba81
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-5xxx/5112/input/index.js
@@ -0,0 +1,1 @@
+function c(r, n) { const e = new Uint8Array(4 * r * r), a = 1, o = -.5, s = Math.sqrt(a * a + o * o), c = (r - n) / 2; return { e, s, c } }
diff --git a/crates/swc/tests/fixture/issues-5xxx/5112/output/index.js b/crates/swc/tests/fixture/issues-5xxx/5112/output/index.js
new file mode 100644
index 0000000000..e3d7a85598
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-5xxx/5112/output/index.js
@@ -0,0 +1,8 @@
+function c(r, n) {
+    let e = new Uint8Array(4 * r * r);
+    return {
+        e,
+        s: Math.sqrt(1 + -(-0.5 * 0.5)),
+        c: (r - n) / 2
+    };
+}