js-beautify
js-beautify copied to clipboard
Fix issue #1929
Description
- Fix for issue#1929 The issue is caused by assuming that a '}' after a case statement always means the end of case block. Modified the code to accommodate the situation where '}' marks the end of another block within the case block, like an if block. Added a variable to record the position of the last case statement, and deindent accordingly for successive case statements.
sample input
case 1:
if (x == 1) {
}
case 2:
func();
Fixes Issue: #1929.
- [x] JavaScript implementation
- [x] Python implementation (NA if HTML beautifier)
- [x] Added Tests to data file(s)
- [NA ] Added command-line option(s) (NA if
- [ NA] README.md documents new feature/option(s)
Is this needed now? or does #1943 also address this?
Is this needed now? or does #1943 also address this?
I wasn't aware of #1943 when I created the pull request. #1943 does address this, but I think the logic doesn't handle the case with multiple indents within a case block. Ex -
case 0:
if(x == 1)
if(y == 2)
if(z == 3)
func();
case 1:
func();
@SM-90 This code looks fine on https://beautifier.io not sure if #1943 changes this :
switch (a) {
case 0:
if (x == 1)
if (y == 2)
if (z == 3)
func();
case 1:
func();
}
@SM-90 This code looks fine on https://beautifier.io not sure if #1943 changes this :
switch (a) { case 0: if (x == 1) if (y == 2) if (z == 3) func(); case 1: func(); }
Hi @bitwiseman , I had verified that my PR #1943 doesn't change this behaviour...thanks