bublejs / buble

https://buble.surge.sh
MIT License
869 stars 67 forks source link

Fix scoping of variables declared in for loops. #233

Closed luiscubal closed 4 years ago

luiscubal commented 4 years ago

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.

mourner commented 4 years ago

Thank you!