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

Missing parenthesis in initializer of for loop #9200

Closed
nicolo-ribaudo opened this issue Jul 10, 2024 · 1 comment · Fixed by #9209
Closed

Missing parenthesis in initializer of for loop #9200

nicolo-ribaudo opened this issue Jul 10, 2024 · 1 comment · Fixed by #9209
Labels
Milestone

Comments

@nicolo-ribaudo
Copy link

nicolo-ribaudo commented Jul 10, 2024

Describe the bug

SWC is removing some parentheses form this for loop, and the resulting code logs 0 instead of 1

Input code

let count = 0;
for (var a = 1 || (2 in {}) in { x: 1 }) count++;
console.log(count);

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": true
    },
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    },
    "target": "es2022"
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": false
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.6.7&code=H4sIAAAAAAAAA8tJLVFIzi%2FNK1GwVTCw5krLL1LQKEssUkgE8g0VamoUNIwUMvMUqms1wZRChRVQWAHIA2vS1rbmSs7PK87PSdXLyU%2FXAAtqWnMBADlkkHNWAAAA&config=H4sIAAAAAAAAA1WPMQ7DIAxF95wCee5QMXToHXoIRJyIKgFkO1KjKHcvJICSDf%2F3P9%2FeOqXgyxbeakvPNERDjNTmpPDqxfySArJGZEsuCjwqFc5IaMEm9WgDGQnEhRxgPzlMITAmMJiJSwZm592wXkttmCMh892YrcaPU8vffhZDI0peFFk%2FtYauMJhDvxyhcmQ%2B5PS9Lqa6RCsEx5%2BaPOv2P70hJh0xAQAA

SWC Info output

No response

Expected behavior

Same code

Actual behavior

let count = 0;
for(var a = 1 || 2 in {} in {
    x: 1
})count++;
console.log(count);

Version

1.6.7

Additional context

Babel has the same bug: babel/babel#16628

@kdy1 kdy1 added this to the Planned milestone Jul 11, 2024
@kdy1 kdy1 self-assigned this Jul 11, 2024
@kdy1 kdy1 removed their assignment Jul 12, 2024
@kdy1 kdy1 closed this as completed in 5cd837f Jul 13, 2024
@kdy1 kdy1 modified the milestones: Planned, v1.7.0 Jul 17, 2024
@swc-bot
Copy link
Collaborator

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