beautifier / js-beautify

Beautifier for javascript
https://beautifier.io
MIT License
8.63k stars 1.38k forks source link

Incorrect formatting when an object literal follows an array declaration without a semicolon #2188

Open lizhihao132 opened 1 year ago

lizhihao132 commented 1 year ago

Description

Input

I've encountered an issue with js-beautify where it incorrectly formats the code when an object literal follows an array declaration without a semicolon. Here's an example of the problematic code:

test()

function test(){
    let a = [122, 234]
    {
        console.info(a)
    }
}

Expected Output

The code should have looked like this after beautification:

test()

function test() {
    let a = [122, 234];
    {
        console.info(a)
    }
}

Actual Output

The code actually looked like this after beautification:

test()

function test() {
    let a = [122, 234] {
        console.info(a)
    }
}

As you can see, the object literal's opening brace is incorrectly placed on the same line as the array declaration, causing the code to become invalid. The expected output should be:

Steps to Reproduce

Environment

OS:

Settings

AryaKS01 commented 1 month ago

can u assign this to me?

bitwiseman commented 1 month ago

@AryaKS01 This project does not assign issues - we have too many folks that never work on an issue after it is assigned to them. Please feel free to work on this and submit a PR.