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 behavior in for loop #8498

Closed
uni-zheng opened this issue Aug 21, 2018 · 4 comments · Fixed by #8937
Closed

wrong behavior in for loop #8498

uni-zheng opened this issue Aug 21, 2018 · 4 comments · Fixed by #8937
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@uni-zheng
Copy link

Bug Report

Current Behavior
Just print log once.

Input Code

  • REPL or Repo link if applicable:
for (let i = 0; i < 3; i++) {
  let i = 'abc';
  console.log(i);
}

Output Code

"use strict";

for (var i = 0; i < 3; i++) {
  var i = "abc";
  console.log(i);
}

Expected behavior/code
print log 3 times

Environment
use https://new.babeljs.io/repl
set presets both es2015 and stage-3
version v6.26.0

Possible Solution
Should create temporary variable in body.

@babel-bot
Copy link
Collaborator

Hey @uni-zheng! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@byronluk
Copy link
Contributor

Hi I'm going to try to look at this. Thanks!

@byronluk
Copy link
Contributor

@nicolo-ribaudo Is it a better choice to add a closure inside the block scope or to rename the block scoped variable that is colliding with the for loop initializer?

@nicolo-ribaudo
Copy link
Member

Renaming the variable would be better, but if it is too complex we can just wrap the for body in a block, like in #8920, since it isn't a common case.

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jan 30, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jan 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants