Skip to content

Commit cf996d2

Browse files
quick fix to part of new issue in #1099:
`not in []` unconditionally compiled to `false`
1 parent 9fef66f commit cf996d2

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

lib/coffee-script/nodes.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/nodes.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -1408,11 +1408,11 @@ exports.In = class In extends Base
14081408
@compileLoopTest o
14091409

14101410
compileOrTest: (o) ->
1411+
return "#{!!@negated}" if @array.base.objects.length is 0
14111412
[sub, ref] = @object.cache o, LEVEL_OP
14121413
[cmp, cnj] = if @negated then [' !== ', ' && '] else [' === ', ' || ']
14131414
tests = for item, i in @array.base.objects
14141415
(if i then ref else sub) + cmp + item.compile o, LEVEL_ACCESS
1415-
return 'false' if tests.length is 0
14161416
tests = tests.join cnj
14171417
if o.level < LEVEL_OP then tests else "(#{tests})"
14181418

test/operators.coffee

+7-4
Original file line numberDiff line numberDiff line change
@@ -199,16 +199,19 @@ test "#1100: precedence in or-test compilation of `in`", ->
199199

200200
test "#1630: `in` should check `hasOwnProperty`", ->
201201
ok undefined not in length: 1
202-
202+
203203
test "#1714: lexer bug with raw range `for` followed by `in`", ->
204204
0 for [1..2]
205205
ok not ('a' in ['b'])
206-
206+
207207
0 for [1..2]; ok not ('a' in ['b'])
208-
208+
209209
0 for [1..10] # comment ending
210210
ok not ('a' in ['b'])
211211

212+
test "#1099: statically determined `not in []` reporting incorrect result", ->
213+
ok 0 not in []
214+
212215

213216
# Chained Comparison
214217

@@ -259,4 +262,4 @@ test "#1102: String literal prevents line continuation", ->
259262

260263
test "#1703, ---x is invalid JS", ->
261264
x = 2
262-
eq (- --x), -1
265+
eq (- --x), -1

0 commit comments

Comments
 (0)