Skip to content

Commit

Permalink
Merge pull request #3322 from xixixao/issue1099
Browse files Browse the repository at this point in the history
Fix #1099, remove in empty array optimization
  • Loading branch information
jashkenas committed Jan 23, 2014
2 parents d2f90d2 + 26dcf02 commit b00962d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 1 addition & 4 deletions lib/coffee-script/nodes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = []
Expand Down
4 changes: 4 additions & 0 deletions test/operators.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b00962d

Please sign in to comment.