1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

fixing inline-loop object-in-array tests for instance variables. Issue #481

This commit is contained in:
Jeremy Ashkenas 2010-07-10 09:01:22 -04:00
parent 2f8a29b5a0
commit 7a16db9ad3
3 changed files with 12 additions and 4 deletions

View file

@ -1218,7 +1218,7 @@
i = _c[0];
l = _c[1];
prefix = this.obj1 !== this.obj2 ? this.obj1 + '; ' : '';
return "!!(function(){ " + (prefix) + "for (var " + i + "=0, " + l + "=" + (this.arr1) + ".length; " + i + "<" + l + "; " + i + "++) if (" + (this.arr2) + "[" + i + "] === " + this.obj2 + ") return true; })()";
return "!!(function(){ " + (prefix) + "for (var " + i + "=0, " + l + "=" + (this.arr1) + ".length; " + i + "<" + l + "; " + i + "++) if (" + (this.arr2) + "[" + i + "] === " + this.obj2 + ") return true; }).call(this)";
};
return InNode;
})();

View file

@ -136,9 +136,9 @@ exports.BaseNode: class BaseNode
class: 'BaseNode'
children: []
unwrap: -> this
unwrap: -> this
isStatement: -> no
isPureStatement: -> no
isPureStatement: -> no
topSensitive: -> no
#### Expressions
@ -1079,7 +1079,7 @@ exports.InNode: class InNode extends BaseNode
[@arr1, @arr2]: @array.compileReference o, {precompile: yes}
[i, l]: [o.scope.freeVariable(), o.scope.freeVariable()]
prefix: if @obj1 isnt @obj2 then @obj1 + '; ' else ''
"!!(function(){ ${prefix}for (var $i=0, $l=${@arr1}.length; $i<$l; $i++) if (${@arr2}[$i] === $@obj2) return true; })()"
"!!(function(){ ${prefix}for (var $i=0, $l=${@arr1}.length; $i<$l; $i++) if (${@arr2}[$i] === $@obj2) return true; }).call(this)"
#### TryNode

View file

@ -51,6 +51,14 @@ list: [1, 2, 7]
result: if list[2] in [7, 10] then 100 else -1
ok result is 100
# And with array presence on an instance variable.
obj: {
list: [1, 2, 3, 4, 5]
in_list: (value) -> value in @list
}
ok obj.in_list 4
ok not obj.in_list 0
# Non-spaced values still work.
x: 10
y: -5