Skip to content

Long condition with experimental-ternaries and no-semi deletes critical semicolon #18965

@zsakowitz

Description

@zsakowitz

Prettier v3.8.1
Playground link

--parser babel
--tab-width 4
--no-semi
--experimental-ternaries

Input:

let o = 1;
(
    1 ||
    12345678901234567890123456789012345678901234567890123456789012345678901234567890
) ?
    2
:   3

Output:

let o = 1
(
    1 ||
    12345678901234567890123456789012345678901234567890123456789012345678901234567890
) ?
    2
:   3

Expected output:

let o = 1
;(
    1 ||
    12345678901234567890123456789012345678901234567890123456789012345678901234567890
) ?
    2
:   3

Why?
The output Prettier gives visibly changes the program, so that it tries to call 1 as a function, instead of assigning it to o. I expect that Prettier should maintain the runtime behavior of the code by inserting a semicolon before the parenthesized ternary condition.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions