js-beautify icon indicating copy to clipboard operation
js-beautify copied to clipboard

Fix issue #1929

Open SM-90 opened this issue 3 years ago • 4 comments

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)

SM-90 avatar Jun 24 '21 16:06 SM-90

Is this needed now? or does #1943 also address this?

bitwiseman avatar Jun 28 '21 23:06 bitwiseman

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 avatar Jul 03 '21 17:07 SM-90

@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();
}

bitwiseman avatar Jul 06 '21 22:07 bitwiseman

@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

pr0grammm avatar Jul 08 '21 13:07 pr0grammm