Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ast: made For::infuseIIFE capture named-destructuring variables

  • Loading branch information...
commit 433f560a63fc8f3775d041d7a441d7156a44102c 1 parent 5dcc678
@satyr authored
Showing with 6 additions and 2 deletions.
  1. +4 −1 lib/ast.js
  2. +1 −0  src/ast.co
  3. +1 −1  test/loop.co
View
5 lib/ast.js
@@ -2784,7 +2784,7 @@ exports.For = For = (function(superclass){
}
}
this.body.traverseChildren(function(it){
- var fun, params, call, index, item;
+ var fun, params, call, index, item, that;
if (!(it.calling || it.op === 'new' && (fun = it.it).params)) {
return;
}
@@ -2802,6 +2802,9 @@ exports.For = For = (function(superclass){
if (index && !dup(params, index)) {
call.args.push(params[params.length] = Var(index));
}
+ if (that = item instanceof List && item.name) {
+ item = Var(that);
+ }
if (item instanceof Var && !dup(params, item.value)) {
call.args.push(params[params.length] = item);
}
View
1  src/ast.co
@@ -1716,6 +1716,7 @@ class exports.For extends While
{index, item} = this
if index and not dup params, index
call.args.push params.* = Var index
+ item = Var that if item instanceof List and item.name
if item instanceof Var and not dup params, item.value
call.args.push params.* = item
View
2  test/loop.co
@@ -236,7 +236,7 @@ eq sums.2, 11
fs = for x, y in {2 3 5} then let z = 7 then -> x * y * z
eq 63 fs.1()
-os = for n of [11 13] then new -> import n: -> n
+os = for [_]:n of [11 13] then new -> import n: -> n
eq 11 os.0.n()
Please sign in to comment.
Something went wrong with that request. Please try again.