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

Fix scoping of variables declared in for loops. #233

Merged
merged 1 commit into from
Dec 13, 2019

Conversation

luiscubal
Copy link
Contributor

This fixes an issue encountered when compiling:

for (let i = 0; i < 10; i++) {
   const i = ...;
   ...
}

Buble incorrectly threw an error due to the 'i' in 'i++' being
incorrectly identified as a constant.
This commits makes it so for, for in and for of loops have their
own scope.

The way the variable declarations are handled to calculate shouldRewriteAsFunction is not ideal. It only got the bare minimum changes to pass the existing tests, so current limitations still apply.

This fixes an issue encountered when compiling:
```
for (let i = 0; i < 10; i++) {
   const i = ...;
   ...
}
```

Buble incorrectly threw an error due to the 'i' in 'i++' being
incorrectly identified as a constant.
This commits makes it so for, for in and for of loops have their
own scope.
@mourner
Copy link
Collaborator

mourner commented Dec 13, 2019

Thank you!

@mourner mourner merged commit e8d0c05 into bublejs:master Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants