Repository: swc-project/swc (rust)

Issue:
Minifier panics: `index out of bounds: the len is 0 but the index is 0`
### Describe the bug

The minifier panics:

```
thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', 
/Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/swc_ecma_minifier-0.154.19/src/compress/pure/evaluate.rs:285:70
```

### Input code

```typescript
foo = {
	v: (0).toFixed(),
};
```


### Config

```json
{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2019",
    "transform": {
      "react": {
        "runtime": "automatic"
      }
    },
    "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
      }
    }
  },
  "isModule": true,
  "module": {
    "type": "es6"
  },
  "minify": true
}
```


### Playground link

https://play.swc.rs/?version=1.3.1&code=H4sIAAAAAAAAA0vLz1ewVajm4iyzUtAw0NQryXfLrEhN0dDU4aq15gIA2l83Nh4AAAA%3D&config=H4sIAAAAAAAAA22TTY7bMAyF72LMMpi0sygwOUB3PYOgSJSjVBYNksoPgty9lJPIcdKd%2BfmRoh6pS%2FfBbgeD7TbdTmTkzXq9Z8yfN8qCBJ9I%2FZqPjly36vbsus2lGy0xUP3icxZ70nRwqncUR5lkioJNDNdVJ5Z6kCrhrx8%2Fv%2FW3kM0ckIZagcA6mT5KljiACm0RHKxE1101f4g5hnNVOBxGAub6rUXLAFn4ftBKCeFRQ6Gi0RYxgR7zGhvLJmaBHmhOdZiSHRnMwVLLqKdZimrHAhUBb0bC8YlmHyVi1mIP5sF649BDA5HASTzALNEaKsmsjbVOJuhhW%2Fq%2BGnxTwsGmYqXVgtNkg57Y8nYYWUwomV%2FQotMbul3yrorBEEih%2FNDsMeaFD38BtM9kmbMdYM6ceNA5LJXhP6qYgw5Rzo0mfOoqQ6%2BXMzGGdsPaNZDE2S0CXxzUG7q5%2BB0uLsTRg4EQ1O2WzMcoutEtlvMIGFqortkwz%2BAWmsc%2BLWldgTf4W7uS53HcuS7x7pXxedhieisxgOzQv2E1QvAVkm7vaXylJXtQm8E%2F%2FShcw7amOnxBk%2BprfPisC6E5pk%2B4bet7rc8u8h%2F0JbWRDPfoMrk3Pedf3dPznBL%2FAW0hT7VRBAAA

### Expected behavior

Works

### Actual behavior

Panics

### Version

1.3.1

### Additional context

```js
let swcConfig = {
    mangle: true,
    compress: true,
    sourceMap: false,
    toplevel: true,
    module: true,
};

swc.minify(fs.readFileSync(INPUT, "utf8"), swcConfig).then(console.log);
```

Pull request:
fix(es/compress): Handle omitted fractionDigits
<!-- 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):**
- fix #5864 

Patch:
diff --git a/crates/swc_ecma_minifier/src/compress/pure/evaluate.rs b/crates/swc_ecma_minifier/src/compress/pure/evaluate.rs
index c568e991cb..a1590d5ed4 100644
--- a/crates/swc_ecma_minifier/src/compress/pure/evaluate.rs
+++ b/crates/swc_ecma_minifier/src/compress/pure/evaluate.rs
@@ -282,7 +282,12 @@ impl Pure<'_> {
         }
 
         if &*method.sym == "toFixed" {
-            if let Some(precision) = eval_as_number(&self.expr_ctx, &args[0].expr) {
+            if let Some(precision) = args
+                .first()
+                // https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.prototype.tofixed
+                // 3. Assert: If fractionDigits is undefined, then f is 0.
+                .map_or(Some(0f64), |arg| eval_as_number(&self.expr_ctx, &arg.expr))
+            {
                 let precision = precision.floor() as usize;
                 let value = num_to_fixed(num.value, precision + 1);
 


Test patch:
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5864/analysis-snapshot.rust-debug b/crates/swc_ecma_minifier/tests/fixture/issues/5864/analysis-snapshot.rust-debug
new file mode 100644
index 0000000000..165d75bda9
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5864/analysis-snapshot.rust-debug
@@ -0,0 +1,42 @@
+TestSnapshot {
+    vars: [
+        (
+            (
+                Atom('foo' type=inline),
+                #1,
+            ),
+            VarUsageInfo {
+                inline_prevented: false,
+                ref_count: 1,
+                cond_init: false,
+                declared: false,
+                declared_count: 0,
+                declared_as_fn_param: false,
+                declared_as_fn_expr: false,
+                assign_count: 0,
+                mutation_by_call_count: 0,
+                usage_count: 0,
+                reassigned_with_assignment: false,
+                reassigned_with_var_decl: false,
+                mutated: true,
+                has_property_access: false,
+                has_property_mutation: false,
+                accessed_props: {},
+                exported: false,
+                used_above_decl: true,
+                is_fn_local: true,
+                used_by_nested_fn: false,
+                executed_multiple_time: false,
+                used_in_cond: false,
+                var_kind: None,
+                var_initialized: true,
+                declared_as_catch_param: false,
+                no_side_effect_for_member_access: false,
+                used_as_callee: false,
+                used_as_arg: false,
+                pure_fn: false,
+                infects: [],
+            },
+        ),
+    ],
+}
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5864/config.json b/crates/swc_ecma_minifier/tests/fixture/issues/5864/config.json
new file mode 100644
index 0000000000..b38da13846
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5864/config.json
@@ -0,0 +1,46 @@
+{
+    "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
+}
\ No newline at end of file
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5864/input.js b/crates/swc_ecma_minifier/tests/fixture/issues/5864/input.js
new file mode 100644
index 0000000000..493b69b574
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5864/input.js
@@ -0,0 +1,3 @@
+foo = {
+    v: (0).toFixed(),
+};
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5864/output.js b/crates/swc_ecma_minifier/tests/fixture/issues/5864/output.js
new file mode 100644
index 0000000000..0475b25685
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5864/output.js
@@ -0,0 +1,3 @@
+foo = {
+    v: "0"
+};
diff --git a/crates/swc_ecma_minifier/tests/fixture/issues/5864/output.mangleOnly.js b/crates/swc_ecma_minifier/tests/fixture/issues/5864/output.mangleOnly.js
new file mode 100644
index 0000000000..19740caacc
--- /dev/null
+++ b/crates/swc_ecma_minifier/tests/fixture/issues/5864/output.mangleOnly.js
@@ -0,0 +1,3 @@
+foo = {
+    v: (0).toFixed()
+};