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

Ternaries with -0 : 0 are removed by compress conditionals #7111

Closed
frec-kenneth opened this issue Mar 21, 2023 · 2 comments · Fixed by #7112
Closed

Ternaries with -0 : 0 are removed by compress conditionals #7111

frec-kenneth opened this issue Mar 21, 2023 · 2 comments · Fixed by #7112
Assignees
Labels
Milestone

Comments

@frec-kenneth
Copy link

Describe the bug

We use decimal.js on our site to manage numbers. It's a popular library.

We found that when we upgraded Next to v13, we saw more negative zeros in production.

Input code

console.log(Math.random()>0.5?-0:0)

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es2022",
    "loose": false,
    "minify": {
      "compress": {
        "arguments": false,
        "arrows": false,
        "booleans": false,
        "booleans_as_integers": false,
        "collapse_vars": false,
        "comparisons": false,
        "computed_props": false,
        "conditionals": true,
        "dead_code": false,
        "directives": false,
        "drop_console": false,
        "drop_debugger": false,
        "evaluate": false,
        "expression": false,
        "hoist_funs": false,
        "hoist_props": false,
        "hoist_vars": false,
        "if_return": false,
        "join_vars": false,
        "keep_classnames": false,
        "keep_fargs": false,
        "keep_fnames": false,
        "keep_infinity": false,
        "loops": false,
        "negate_iife": false,
        "properties": false,
        "reduce_funcs": false,
        "reduce_vars": false,
        "side_effects": false,
        "switches": false,
        "typeofs": false,
        "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,
        "const_to_let": false,
        "pristine_globals": false
      },
      "mangle": false
    }
  },
  "module": {
    "type": "systemjs"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.3.41&code=H4sIAAAAAAAAA0vOzyvOz0nVy8lP1%2FBNLMnQK0rMS8nP1dC0M9Aztdc1sDLQBADE0KwtIwAAAA%3D%3D&config=H4sIAAAAAAAAA32UO5LbMAyGe5%2FCozpFxkWKPUC6nIFDi6BMhyQ0BOi1Z8d3D%2FTwIwmoTsIHEMQPEF%2B7%2Fb47U9997L%2FkU35GWwjK818sdMtsr2LpoE%2BW%2BhJG7r496Jkm5G0kmE33hXRsywA8R9Hh%2B%2BGwRnQRkeARsdpSyMHf3nP2mMYCRG82scqRNUFm%2Bjt%2BZQU%2FNXBEjGDzFjKWTMgMAxTNrccY7UhgLrbBk6gWCNUkE60MzowFR90hu8ABs9gFc6nv1IF1pkcHSqQLBXoOF9COdZJOAjNJjS3s4FiHYW73vxwuNlbLWihc597IjRV4wkBsfFW1WGBLiIU2RA7eFOBatJxnDLkV9xtAZIiWKNukCjV7eJmtNtwMDdnL%2FPJN4TLsaqUZBpHWhOA1fSd9oHBQUxZwtYdJ4H4DN8Sg4MCA9zI1Kv4M3J%2FUtHwbAb1GpNNWLWMBpvkwVz69jw38UwplfdRWj2T51KZ0S0eMGwkS8AndhoO0g7GNi6yN69jmNTuQAQGnulRSwfRu2TCaOO%2FQ%2FydEXoqcaYaIR%2FuqbvW4P7dzsnl4Pf9lQe9Why6hqzNcV%2F%2FU42Vh%2F%2BheTo%2Fd%2FLxDF%2BjXI3JaVrv7Hw2oLXNGBgAA

Expected behavior

console.log(Math.random() > 0.5 ? -0 : 0);

Actual behavior

console.log(-0)

Version

1.3.41

Additional context

While 0 === -0 is true in JavaScript, they are different, and this condition should not be removed.

@kdy1 kdy1 added this to the Planned milestone Mar 21, 2023
@kdy1 kdy1 self-assigned this Mar 21, 2023
kdy1 added a commit that referenced this issue Mar 21, 2023
@frec-kenneth
Copy link
Author

Wow, that was fast! Thanks!

@kdy1 kdy1 modified the milestones: Planned, v1.3.42 Mar 22, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Apr 21, 2023

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 Apr 21, 2023
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