nested shared scopes don't clobber variables.

This commit is contained in:
Jeremy Ashkenas
2010-11-27 17:52:52 -08:00
parent 63cbb64341
commit 39c4c23200
4 changed files with 12 additions and 2 deletions

View File

@@ -49,9 +49,8 @@
return compileScripts();
};
compileScripts = function() {
var _fn, _i, _len, _results;
var base, compile, _fn, _i, _len, _results;
_fn = function(source) {
var base, compile;
base = path.join(source);
compile = function(source, topLevel) {
return path.exists(source, function(exists) {

View File

@@ -1880,6 +1880,7 @@
args.unshift(new Literal('this'));
}
body.expressions[idx] = new Call(base, args);
o.sharedScope = o.scope;
defs += this.tab + new Assign(ref, fn).compile(o, LEVEL_TOP) + ';\n';
}
return defs;

View File

@@ -1498,6 +1498,7 @@ exports.For = class For extends Base
[val.base, base] = [base, val]
args.unshift new Literal 'this'
body.expressions[idx] = new Call base, args
o.sharedScope = o.scope
defs += @tab + new Assign(ref, fn).compile(o, LEVEL_TOP) + ';\n'
defs

View File

@@ -219,3 +219,12 @@ odds = while i--
i
ok odds.join(', ') is '5, 3, 1'
# Nested shared scopes.
foo = ->
for i in [0..7]
for j in [0..7]
-> i + j
eq foo()[3][4](), 7