Skip to content

Commit

Permalink
quick fix to part of new issue in #1099:
Browse files Browse the repository at this point in the history
`not in []` unconditionally compiled to `false`
  • Loading branch information
michaelficarra committed Oct 3, 2011
1 parent 9fef66f commit cf996d2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/coffee-script/nodes.js

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

2 changes: 1 addition & 1 deletion src/nodes.coffee
Expand Up @@ -1408,11 +1408,11 @@ exports.In = class In extends Base
@compileLoopTest o

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

Expand Down
11 changes: 7 additions & 4 deletions test/operators.coffee
Expand Up @@ -199,16 +199,19 @@ test "#1100: precedence in or-test compilation of `in`", ->

test "#1630: `in` should check `hasOwnProperty`", ->
ok undefined not in length: 1

test "#1714: lexer bug with raw range `for` followed by `in`", ->
0 for [1..2]
ok not ('a' in ['b'])

0 for [1..2]; ok not ('a' in ['b'])

0 for [1..10] # comment ending
ok not ('a' in ['b'])

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


# Chained Comparison

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

test "#1703, ---x is invalid JS", ->
x = 2
eq (- --x), -1
eq (- --x), -1

0 comments on commit cf996d2

Please sign in to comment.