mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Remove in empty array optimization
This commit is contained in:
parent
39cb8815f7
commit
26dcf025f4
3 changed files with 6 additions and 6 deletions
|
@ -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 = [];
|
||||
|
|
|
@ -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 = []
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue