Handle switch case statements without a break #84
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.