Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Handle switch case statements without a break #84
Case statements with no break should run subsequent case statements until a break is reached.
In the last example, when letter is 'a', both a_only() and a_and_b() should be called. There are a couple ways I could have gone here:
Storing functions to call:
The former will be awkward when switch case statements use many chained cases (no break) and have lots of code. The latter really isn't too bad, but I don't feel confident about a few things, such as _cases not overwriting real variables, and actually coding this in js2coffee. This is my first time looking at the project.
That said, I decided to go with the former for now. Let me know if you disagree with that approach.
Tests have been updated and pass. Notably, the returns test was updated to include break statements to avoid redundantly testing this feature since it is tested by the switch test.
I only recently was aware of #76, which I think more elegantly solves this problem. Even though it doesn't handle normal fall-through cases yet, I like the method @chills42 suggested using a conditional block. Much better than duplicating the code.
@michaelficarra Could you clarify what you meant about control flow though?