Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lizhihao132 opened this issue Aug 22, 2023 · 0 comments

Comments

@lizhihao132
Copy link

lizhihao132 commented Aug 22, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant