Skip to content

Bug: using "not in" operator in switch works as "in" instead #5480

@hendricha

Description

@hendricha
switch
  when thing in arr
    console.log 'this'
  when thing not in arr
    console.log 'that'

Expected Behavior

The above should probably compile to something along the lines of this:

var indexOf = [].indexOf;

switch (false) {
  case indexOf.call(arr, thing) < 0:
    console.log('this');
    break;
  case indexOf.call(arr, thing) >= 0:
    console.log('that');
}

Current Behavior

It however compiles to this:

var indexOf = [].indexOf;

switch (false) {
  case indexOf.call(arr, thing) < 0:
    console.log('this');
    break;
  case indexOf.call(arr, thing) < 0:
    console.log('that');
}

Environment

  • CoffeeScript version: 2.7.0
  • Node.js version: some version of 14 for legacy reasons
    But the thing happens even on the "try coffeescript" page on the website too

Other context

This does not happen in coffee v1 nor in civet with coffee compat

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions