From cf996d2c4a9abf335bbcb7829ed6d7a67b807398 Mon Sep 17 00:00:00 2001 From: Michael Ficarra Date: Mon, 3 Oct 2011 06:43:00 -0400 Subject: [PATCH] quick fix to part of new issue in #1099: `not in []` unconditionally compiled to `false` --- lib/coffee-script/nodes.js | 2 +- src/nodes.coffee | 2 +- test/operators.coffee | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/coffee-script/nodes.js b/lib/coffee-script/nodes.js index 322c1d23..07ee1224 100644 --- a/lib/coffee-script/nodes.js +++ b/lib/coffee-script/nodes.js @@ -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; diff --git a/src/nodes.coffee b/src/nodes.coffee index 07ceb8d3..08eedcf5 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -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})" diff --git a/test/operators.coffee b/test/operators.coffee index 79d77134..2391ee9e 100644 --- a/test/operators.coffee +++ b/test/operators.coffee @@ -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 \ No newline at end of file + eq (- --x), -1