-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Inconsistent index variable values after loop/comprehension #781
Conversation
See the tests added to test_comprehensions.coffee. Previously, after `for i in [1..3]`, i was 4. Also, index variables were never set to any value in comprehensions containing both a closure and a break or return.
What's with all the two line spaces in the generated JS? |
Sorry; wasn't looking at the generated JS, just seeing if the tests passed. I pushed a fix: http://github.com/TrevorBurnham/coffee-script/commit/33ac70aec349eb91151f5fe0a1a562120eabf456 |
The pure statement thing was my fault, I tidied that up a bit. |
Is this for range case only? |
Yeah. |
Really? I'd expect identical results from them:
And what about these?
|
It's implied that the That |
We've got variable step, so it's more complicated. |
Yeah, I'd rather kill the magic as well, in exchange for an easier way to boot up a new scope without having to use |
Now that index variables are definitely preserved from loops (issue 118), I think it behooves us to correct this behavior:
I'd call that last case a bug; the fix is to undo one step at the end of any
for
loop where the index variable is named.Also,
i
should always have the last step in case of abreak
orreturn
, buti
's value is never set at all if there's a closure and abreak
orreturn
anywhere!I've added corresponding test cases to
test_comprehensions.coffee
and patchednodes.coffee
. Yes, the hairiest method in the CoffeeScript compiler just got slightly hairier...