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

Emit for (const x of ...) instead of for (let x of ...) #1266

Open
joliss opened this issue Mar 15, 2018 · 1 comment
Open

Emit for (const x of ...) instead of for (let x of ...) #1266

joliss opened this issue Mar 15, 2018 · 1 comment

Comments

@joliss
Copy link

joliss commented Mar 15, 2018

ESLint caught the following unnecessary let (repl):

for x of arr
  f(x)

compiles into

for (let x in arr) {
  f(x);
}

when it could compile into

for (const x in arr) {
  f(x);
}

as long as x is not reassigned inside the loop.

@alangpierce
Copy link
Member

Thanks for reporting! FWIW, eslint --fix will correct this for you, which is why it hasn't caused trouble in my use of decaffeinate, but agreed that it would be nice if decaffeinate itself generated code using const.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants