Handle switch case statements without a break#84
Conversation
The returns test was updated to include break statements to avoid redundantly testing this feature, since it is tested by the switch test.
|
big -1, this patch fails in numerous ways with regards to flow control |
|
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? |
|
#91 pointed out the fact that http://phpjs.org/functions/version_compare:852 would not compile properly. Use your fork to compile it. The output is horribly ugly and, worse yet, incorrect. The |
|
Thanks for testing that. I should have tested it on something more complex like the script you linked. |
|
No problem, I love testing things out and reviewing code. |
Problems
This valid javascript produces this error: TypeError: Cannot call method 'isA' of undefined
Case statements with no break should run subsequent case statements until a break is reached.
This code javascript compiles into this coffeescript, which fails to run a_and_b() when letter is 'a':
Proposed solution
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:
Redundancy:
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.
Testing
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.