preface
This probably has no real implementation but after reading another post on coffeescript's 2 switch usages, I decided to play around with it and found this rather odd issue.
coffeescript
type = 'guidance'
s = switch
when type is 'guidance'
'g'
when type is 'vulnerability'
'v'
else
'foo'
console.log s #g
transpiled javascript
var s, type;
type = 'guidance';
s = (function() {
switch (false) {
case type !== 'guidance':
return 'g';
case type !== 'vulnerability':
return 'v';
default:
return 'foo';
}
})();
console.log(s); //g
the conundrum
What I don't get is that the case expressions are being compiled to the opposite value. The Coffeescript when type is 'guidance'
should transpile to the following javascript case type === 'guidance'
right?
If you use s = switch true
then the case expressions are rendered correctly case type === 'guidance'
. Regardless of the rendered javaScript case expressions, the result is the same.