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

quick fix to part of new issue in #1099:

`not in []` unconditionally compiled to `false`
This commit is contained in:
Michael Ficarra 2011-10-03 06:43:00 -04:00
parent 9fef66ffcf
commit cf996d2c4a
3 changed files with 9 additions and 6 deletions

View file

@ -1892,6 +1892,7 @@
In.prototype.compileOrTest = function(o) {
var cmp, cnj, i, item, ref, sub, tests, _ref2, _ref3;
if (this.array.base.objects.length === 0) return "" + (!!this.negated);
_ref2 = this.object.cache(o, LEVEL_OP), sub = _ref2[0], ref = _ref2[1];
_ref3 = this.negated ? [' !== ', ' && '] : [' === ', ' || '], cmp = _ref3[0], cnj = _ref3[1];
tests = (function() {
@ -1904,7 +1905,6 @@
}
return _results;
}).call(this);
if (tests.length === 0) return 'false';
tests = tests.join(cnj);
if (o.level < LEVEL_OP) {
return tests;

View file

@ -1408,11 +1408,11 @@ exports.In = class In extends Base
@compileLoopTest o
compileOrTest: (o) ->
return "#{!!@negated}" if @array.base.objects.length is 0
[sub, ref] = @object.cache o, LEVEL_OP
[cmp, cnj] = if @negated then [' !== ', ' && '] else [' === ', ' || ']
tests = for item, i in @array.base.objects
(if i then ref else sub) + cmp + item.compile o, LEVEL_ACCESS
return 'false' if tests.length is 0
tests = tests.join cnj
if o.level < LEVEL_OP then tests else "(#{tests})"

View file

@ -199,16 +199,19 @@ test "#1100: precedence in or-test compilation of `in`", ->
test "#1630: `in` should check `hasOwnProperty`", ->
ok undefined not in length: 1
test "#1714: lexer bug with raw range `for` followed by `in`", ->
0 for [1..2]
ok not ('a' in ['b'])
0 for [1..2]; ok not ('a' in ['b'])
0 for [1..10] # comment ending
ok not ('a' in ['b'])
test "#1099: statically determined `not in []` reporting incorrect result", ->
ok 0 not in []
# Chained Comparison
@ -259,4 +262,4 @@ test "#1102: String literal prevents line continuation", ->
test "#1703, ---x is invalid JS", ->
x = 2
eq (- --x), -1
eq (- --x), -1