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:
parent
2f8a29b5a0
commit
7a16db9ad3
3 changed files with 12 additions and 4 deletions
|
@ -1218,7 +1218,7 @@
|
||||||
i = _c[0];
|
i = _c[0];
|
||||||
l = _c[1];
|
l = _c[1];
|
||||||
prefix = this.obj1 !== this.obj2 ? this.obj1 + '; ' : '';
|
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;
|
return InNode;
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -136,9 +136,9 @@ exports.BaseNode: class BaseNode
|
||||||
class: 'BaseNode'
|
class: 'BaseNode'
|
||||||
children: []
|
children: []
|
||||||
|
|
||||||
unwrap: -> this
|
unwrap: -> this
|
||||||
isStatement: -> no
|
isStatement: -> no
|
||||||
isPureStatement: -> no
|
isPureStatement: -> no
|
||||||
topSensitive: -> no
|
topSensitive: -> no
|
||||||
|
|
||||||
#### Expressions
|
#### Expressions
|
||||||
|
@ -1079,7 +1079,7 @@ exports.InNode: class InNode extends BaseNode
|
||||||
[@arr1, @arr2]: @array.compileReference o, {precompile: yes}
|
[@arr1, @arr2]: @array.compileReference o, {precompile: yes}
|
||||||
[i, l]: [o.scope.freeVariable(), o.scope.freeVariable()]
|
[i, l]: [o.scope.freeVariable(), o.scope.freeVariable()]
|
||||||
prefix: if @obj1 isnt @obj2 then @obj1 + '; ' else ''
|
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
|
#### TryNode
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,14 @@ list: [1, 2, 7]
|
||||||
result: if list[2] in [7, 10] then 100 else -1
|
result: if list[2] in [7, 10] then 100 else -1
|
||||||
ok result is 100
|
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.
|
# Non-spaced values still work.
|
||||||
x: 10
|
x: 10
|
||||||
y: -5
|
y: -5
|
||||||
|
|
Loading…
Add table
Reference in a new issue