Skip to content

Commit

Permalink
Issue #1354, 'in' with splatted arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed May 15, 2011
1 parent 15ddb8e commit d91ccd4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/nodes.js

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

4 changes: 3 additions & 1 deletion src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,9 @@ exports.In = class In extends Base
invert: NEGATE

compileNode: (o) ->
if @array instanceof Value and @array.isArray()
isArray = @array instanceof Value and @array.isArray()
splat = obj for obj in @array.base.objects when obj instanceof Splat if isArray
if isArray and not splat
@compileOrTest o
else
@compileLoopTest o
Expand Down
4 changes: 4 additions & 0 deletions test/operators.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ test "#768: `in` should preserve evaluation order", ->
test "#1099: empty array after `in` should compile to `false`", ->
eq 1, [5 in []].length
eq false, do -> return 0 in []

test "#1354: optimized `in` checks should not happen when splats are present", ->
a = [6, 9]
eq 9 in [3, a...], true


# Chained Comparison
Expand Down

0 comments on commit d91ccd4

Please sign in to comment.