Skip to content

Commit d91ccd4

Browse files
committed
Issue #1354, 'in' with splatted arrays.
1 parent 15ddb8e commit d91ccd4

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

lib/nodes.js

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,9 @@ exports.In = class In extends Base
13551355
invert: NEGATE
13561356

13571357
compileNode: (o) ->
1358-
if @array instanceof Value and @array.isArray()
1358+
isArray = @array instanceof Value and @array.isArray()
1359+
splat = obj for obj in @array.base.objects when obj instanceof Splat if isArray
1360+
if isArray and not splat
13591361
@compileOrTest o
13601362
else
13611363
@compileLoopTest o

test/operators.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ test "#768: `in` should preserve evaluation order", ->
187187
test "#1099: empty array after `in` should compile to `false`", ->
188188
eq 1, [5 in []].length
189189
eq false, do -> return 0 in []
190+
191+
test "#1354: optimized `in` checks should not happen when splats are present", ->
192+
a = [6, 9]
193+
eq 9 in [3, a...], true
190194

191195

192196
# Chained Comparison

0 commit comments

Comments
 (0)