Bug 435936

Summary: Auto indentation in JS goes berserk inside anonymous function
Product: [Applications] kate Reporter: php4fan
Component: indentationAssignee: KWrite Developers <kwrite-bugs-null>
Status: RESOLVED FIXED    
Severity: grave CC: waqar.17a
Priority: NOR    
Version First Reported In: 20.12.3   
Target Milestone: ---   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: screenshot

Description php4fan 2021-04-19 19:29:26 UTC
Created attachment 137713 [details]
screenshot

SUMMARY


STEPS TO REPRODUCE
1. Create a new .js file and copy this code into it:

document.addEventListener('click', function(event) {
    if (false) console.log("whatever");
});


2. Place the cursor at the end of the middle line, after the ";"
3. Hit the Enter key

OBSERVED RESULT

The new line is insanely indented, 


EXPECTED RESULT

the new line should have the same indentation as the "if" line.


Note that if you try the same outside of the addEventListener(...), it works as expected.

Also, as far as I can tell, generally speaking, inside the function body auto indentation is not generally broken. Most of the time it works as expected but it breaks with the one-line "if" statement without {}s.

By changing the above code to:

document.addEventListener('click', function(event) {
    if (false) {
        console.log("whatever");
    }
});

I don't observe any weirdness in autoindentation.

So, neither the anonymous function inside a function argument list alone, nor the one-line if statement without {} alone, are enough to cause unexpected behavior, but somehow the combination of the two things is.




SOFTWARE/OS VERSIONS

Operating System: openSUSE Tumbleweed 20210414
KDE Plasma Version: 5.21.4
KDE Frameworks Version: 5.81.0
Qt Version: 5.15.2
Kernel Version: 5.11.12-1-default
OS Type: 64-bit
Graphics Platform: X11
Processors: 8 × Intel® Core™ i7-1065G7 CPU @ 1.30GHz
Memory: 7.3 GiB of RAM
Graphics Processor: Mesa DRI Intel® Iris® Plus Graphics

ADDITIONAL INFORMATION
Comment 1 Waqar Ahmed 2022-03-23 14:31:10 UTC
Fixed in 5.91