From 26dcf025f4d3d74e49d79ab0eb8ee1d1dd9c1af3 Mon Sep 17 00:00:00 2001 From: xixixao Date: Wed, 22 Jan 2014 13:18:50 +0000 Subject: [PATCH] Remove in empty array optimization --- lib/coffee-script/nodes.js | 5 +---- src/nodes.coffee | 3 +-- test/operators.coffee | 4 ++++ 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/coffee-script/nodes.js b/lib/coffee-script/nodes.js index 99b01ca9..7974be3d 100644 --- a/lib/coffee-script/nodes.js +++ b/lib/coffee-script/nodes.js @@ -2409,7 +2409,7 @@ In.prototype.compileNode = function(o) { var hasSplat, obj, _i, _len, _ref2; - if (this.array instanceof Value && this.array.isArray()) { + if (this.array instanceof Value && this.array.isArray() && this.array.base.objects.length) { _ref2 = this.array.base.objects; for (_i = 0, _len = _ref2.length; _i < _len; _i++) { obj = _ref2[_i]; @@ -2428,9 +2428,6 @@ In.prototype.compileOrTest = function(o) { var cmp, cnj, i, item, ref, sub, tests, _i, _len, _ref2, _ref3, _ref4; - if (this.array.base.objects.length === 0) { - return [this.makeCode("" + (!!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 = []; diff --git a/src/nodes.coffee b/src/nodes.coffee index 30249286..b87e10c5 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1719,7 +1719,7 @@ exports.In = class In extends Base invert: NEGATE compileNode: (o) -> - if @array instanceof Value and @array.isArray() + if @array instanceof Value and @array.isArray() and @array.base.objects.length for obj in @array.base.objects when obj instanceof Splat hasSplat = yes break @@ -1728,7 +1728,6 @@ exports.In = class In extends Base @compileLoopTest o compileOrTest: (o) -> - return [@makeCode("#{!!@negated}")] if @array.base.objects.length is 0 [sub, ref] = @object.cache o, LEVEL_OP [cmp, cnj] = if @negated then [' !== ', ' && '] else [' === ', ' || '] tests = [] diff --git a/test/operators.coffee b/test/operators.coffee index 20dbd47b..0bbdf84b 100644 --- a/test/operators.coffee +++ b/test/operators.coffee @@ -218,6 +218,10 @@ test "#1714: lexer bug with raw range `for` followed by `in`", -> test "#1099: statically determined `not in []` reporting incorrect result", -> ok 0 not in [] +test "#1099: make sure expression tested gets evaluted when array is empty", -> + a = 0 + (do -> a = 1) in [] + eq a, 1 # Chained Comparison