Issue #905. Fixing soaked-value-as-a-comprehension-subject ... incorrect LEVEL_TOP.

This commit is contained in:
Jeremy Ashkenas
2010-12-09 21:03:41 -05:00
parent a24a3c565e
commit 7b9286b2c2
3 changed files with 10 additions and 2 deletions

View File

@@ -1800,7 +1800,7 @@
step: this.step
}));
} else {
svar = this.source.compile(o, LEVEL_TOP);
svar = this.source.compile(o, LEVEL_PAREN);
if ((name || this.own) && !IDENTIFIER.test(svar)) {
defPart = "" + this.tab + (ref = scope.freeVariable('ref')) + " = " + svar + ";\n";
svar = ref;

View File

@@ -1438,7 +1438,7 @@ exports.For = class For extends Base
if @range
forPart = source.compile merge(o, {index: ivar, @step})
else
svar = @source.compile o, LEVEL_TOP
svar = @source.compile o, LEVEL_PAREN
if (name or @own) and not IDENTIFIER.test svar
defPart = "#{@tab}#{ref = scope.freeVariable 'ref'} = #{svar};\n"
svar = ref

View File

@@ -241,3 +241,11 @@ list = ['one', 'two']
eq typeof entity, 'undefined'
eq facets['two'](), 'two'
# Issue #905. Soaks as the for loop subject.
a = {b: {c: [1, 2, 3]}}
for d in a.b?.c
e = d
eq e, 3