Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/coffeescript/nodes.js

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

5 changes: 4 additions & 1 deletion src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4686,7 +4686,10 @@ exports.Op = class Op extends Base

invert: ->
if @isInOperator()
@invertOperator = '!'
if @invertOperator
@invertOperator = undefined
else
@invertOperator = '!'
return @
if @isChain()
allInvertable = yes
Expand Down
23 changes: 23 additions & 0 deletions test/operators.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,26 @@ test "'new' target", ->

# classes must be called with `new`. In this case `new` applies to `get` only
throws -> new get()()

test "#5480: 'when a not in b'", ->
needle = "needle"
hayStack = []
needleStack = [needle]

switch
when needle in hayStack then ok false
switch
when needle not in hayStack then ok true
switch
when needle in needleStack then ok true
switch
when needle not in needleStack then ok false

switch "with subject"
when needle in hayStack then ok false
switch "with subject"
when needle not in hayStack then ok true
switch "with subject"
when needle in needleStack then ok true
switch "with subject"
when needle not in needleStack then ok false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these switch constructs always hit the default branch because the string is never a boolean

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I updated the tests by adding "and true" after all the strings.

Loading