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

Wrong dead code elimination with variable named Infinity #7683

Closed
nicolo-ribaudo opened this issue Jul 20, 2023 · 1 comment · Fixed by #7684
Closed

Wrong dead code elimination with variable named Infinity #7683

nicolo-ribaudo opened this issue Jul 20, 2023 · 1 comment · Fixed by #7684
Labels
Milestone

Comments

@nicolo-ribaudo
Copy link

Describe the bug

The identifier Infinity might refer to a local variable whose value is not ∞, but SWC assumes that it's always ∞.

Input code

{
  let Infinity = 3;
  if (Infinity > 4) console.log(3)
}

Config

{
  "minify": true,
  "jsc": {
    "minify": {
      "compress": {
        "dead_code": true
      }
    },
    "parser": {
      "syntax": "typescript"
    },
    "target": "es2022"
  }
}

Playground link

https://play.swc.rs/?version=1.3.70&code=H4sIAAAAAAAAA6vmUlDISS1R8MxLy8zLLKlUsFUwtgaKZaYpaMDF7BRMNBWS8%2FOK83NS9XLy0zWMNblqAbTYNkc6AAAA&config=H4sIAAAAAAAAA1WMMQ6AIAxFd09BmB0Mo5cxBKrBRCVtTSSGu1vEAaf2v9%2B%2Bu1NKb2EPc9KjYjyhL2QlJ%2FGWta1rFuKOLSIQNUyoB%2Bsnd3j4TF%2BT35n7KosWCbCVUdrZXkI0pwjkMETWvx%2B2uACXCyAzGFPa3OUHviUI6bwAAAA%3D

Expected behavior

The generated code should either be empty, or still have the if check before console.log. The console.log statement should not be executed.

Actual behavior

The generated code is

console.log(3);

Version

1.3.70

Additional context

No response

@kdy1 kdy1 added this to the Planned milestone Jul 20, 2023
kdy1 pushed a commit that referenced this issue Jul 21, 2023
@kdy1 kdy1 modified the milestones: Planned, v1.3.71 Jul 25, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Aug 24, 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 Aug 24, 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