Bug 435936 - Auto indentation in JS goes berserk inside anonymous function
Summary: Auto indentation in JS goes berserk inside anonymous function
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: indentation (show other bugs)
Version: 20.12.3
Platform: openSUSE Linux
: NOR grave
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-19 19:29 UTC by php4fan
Modified: 2022-03-23 14:31 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
screenshot (11.17 KB, image/png)
2021-04-19 19:29 UTC, php4fan
Details

Note You need to log in before you can comment on or make changes to this bug.
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