Skip to content
Browse files

fix a bug that chris found, in nested for .. of loops

  • Loading branch information...
1 parent 1c84d03 commit 47d6dc25d2ef9a0cb37ae7213d6428515774934f @maxtaco committed Jan 17, 2012
Showing with 21 additions and 3 deletions.
  1. +3 −2 lib/coffee-script/nodes.js
  2. +2 −1 src/nodes.coffee
  3. +16 −0 test/tame.coffee
View
5 lib/coffee-script/nodes.js
@@ -3038,7 +3038,7 @@
For.prototype.children = ['body', 'source', 'guard', 'step'];
For.prototype.compileTame = function(o, d) {
- var a1, a2, a3, a4, a5, b, body, condition, empty_arr, init, ival, key, key_lit, key_val, keys, keys_access, keys_len, keys_val, kval, len, len_rhs, len_val, loop_body, loop_keys, loop_source, ref, ref_val, ref_val_copy, rvar, scope, source_access, step;
+ var a1, a2, a3, a4, a5, b, body, condition, empty_arr, iname, init, ival, key, key_lit, key_val, keys, keys_access, keys_len, keys_val, kval, len, len_rhs, len_val, loop_body, loop_keys, loop_source, ref, ref_val, ref_val_copy, rvar, scope, source_access, step;
if (!this.tameNodeFlag) return null;
body = d.body;
condition = null;
@@ -3063,7 +3063,8 @@
};
loop_keys = new For(loop_body, loop_source);
a2 = new Assign(keys_val, loop_keys);
- ival = new Value(new Literal('i'));
+ iname = scope.freeVariable('i');
+ ival = new Value(new Literal(iname));
a3 = new Assign(ival, new Value(new Literal(0)));
init = [a1, a2, a3];
keys_len = keys_val.copy();
View
3 src/nodes.coffee
@@ -2552,7 +2552,8 @@ exports.For = class For extends While
a2 = new Assign keys_val, loop_keys
# _i = 0
- ival = new Value new Literal 'i'
+ iname = scope.freeVariable 'i'
+ ival = new Value new Literal iname
a3 = new Assign ival, new Value new Literal 0
init = [ a1, a2, a3 ]
View
16 test/tame.coffee
@@ -506,3 +506,19 @@ atest 'super with no args', (cb) ->
await a.foo defer()
cb(a.x is 10, {})
+atest 'nested for .. of .. loops', (cb) ->
+ x =
+ christian:
+ age: 36
+ last: "rudder"
+ max:
+ age: 34
+ last: "krohn"
+
+ tot = 0
+ for first, info of x
+ tot += info.age
+ for k,v of info
+ await delay defer()
+ tot++
+ cb(tot is 74, {})

0 comments on commit 47d6dc2

Please sign in to comment.
Something went wrong with that request. Please try again.