jashkenas/coffee-script — Issue #2164: switch statements: why indent when and else clauses?
Author: erisdiscord
Created: 2012-02-29 22:31:33+00:00
State: open

Currently, switch statements require two levels of indentation, but a `switch` followed by anything but `when` doesn't make any sense. I propose that the compiler ought to know to close a switch statement if it encounters anything at the same indentation level that isn't either `when …` or `else`.

# this switch statement's when clauses are not indented
switch letter
when 'a'
console.log 'alpha'
when 'b'
console.log 'beta'
else
console.log 'whatever'

# this doesn't make sense as part of the switch, so close it
doSomething()

The intended meaning here should be pretty clear even without the extra level of indentation.