swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.22k stars 1.23k forks source link

minifier: invalid handling of exponentiate with `NaN` exponent #8942

Closed hyp3rflow closed 6 months ago

hyp3rflow commented 6 months ago

Describe the bug

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

Input code

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

Config

{
  "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

swc-bot commented 5 months ago

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.