Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minifier: Evaluates value of Math.min/Math.max incorrectly in different argument order #9007

Closed
hyp3rflow opened this issue Jun 1, 2024 · 1 comment · Fixed by #9012
Closed
Assignees
Labels
Milestone

Comments

@hyp3rflow
Copy link
Sponsor Contributor

Describe the bug

The inlined result should be same even if the argument order is changed.

Input code

console.log(Math.min(-0, 0))
console.log(Math.min(0, -0))
console.log(Math.max(-0, 0))
console.log(Math.max(0, -0))

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es5",
    "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": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.5.24&code=H4sIAAAAAAAAA0vOzyvOz0nVy8lP1%2FBNLMnQy83M09A10FEw0NTkSsYmCZTTxS6ZWIFHJ1ASqhMARowy1HMAAAA%3D&config=H4sIAAAAAAAAA42VzW7bMAyA732KwOcdtsOAYg%2Bw255BUCzKUSaJhkilCYq8%2B2jFTtOGNnYJYn78ESmSen%2FZ7boj9d2v3bv8lY%2FRFoJy%2FxYJXTLbs0g66JOlvoSRu28LPdKEvI0ETXS9kY5tGYCbFf2c1buISLCoz7IUcvCXx4A9prEA0YNMpOKvJshMn%2B1nVvBtAlzqo3yPGMHmDWIsmZAZBiia4x5jtCOBOdmieJlOaksg1EJMsDI4MxYcVZ5d4IBZYj5TB9aZHh0oKBToOZxAM5NYYpZJ0lPyadjBvg5Du%2BQv1nCysVpWYsK5XYmcVvF6wEBsfM1aCW9wpQY3OBf3q2XwpgDXkp%2Ftjhjyyp38BZAKREuUbQLNb9Pw0k9r1n7TMmQvLcsXhUt%2Fa1lmGKSoJgSvVHaqDBQO2m0WcLWHqbK9dpwZr5SPggMD3kuvKK7pLXB%2F0ILyZQT0CpD7tV7rqhsw9ylc4dNAbODfkiXrDTZrJMuHdUqXtMe4ESABH9BtKMhVMK7jIlviPK7zmh1Ia4BTVSo18LwEZAAYTWzL8qk3ZDzEoxki7j%2FWxKxwvS%2FhZPPQ5v1hXzKOEU4Q19r4P0Zkk8rZTlNXL5P9NL3wqjWllcELP75%2FejMklZfltyXVJXT1IaHWk9NbIi2UMB%2Bp%2B9Bcno97pC7Qn8W8Vev6D4dGmLPmBgAA

SWC Info output

No response

Expected behavior

console.log(-0)
console.log(-0)
console.log(0)
console.log(0)

Actual behavior

console.log(0)
console.log(-0)
console.log(-0)
console.log(0)

Version

1.5.24

Additional context

No response

@hyp3rflow hyp3rflow added the C-bug label Jun 1, 2024
@kdy1 kdy1 self-assigned this Jun 1, 2024
@kdy1 kdy1 added this to the Planned milestone Jun 1, 2024
@kdy1 kdy1 closed this as completed in #9012 Jun 2, 2024
kdy1 added a commit that referenced this issue Jun 2, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.5.25 Jun 5, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Jul 5, 2024

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.

@swc-project swc-project locked as resolved and limited conversation to collaborators Jul 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants