Skip to content

ternary operator > lambda > ternary fails to parse himself after formatting #2194

@deddu

Description

@deddu

The following nested ternary

let icecream = what == "cone"
  ? p => !!p ? `here's your ${p} cone` : `just the empty cone for you`
  : p => `here's your ${p} ${what}`;

gets formatted to

let icecream = what == "cone"
  ? p => (!!p ? `here's your ${p} cone` : `just the empty cone for you`)
  : p => `here's your ${p} ${what}`;

which consequently fails a subsequent parsing with
SyntaxError: Invalid left-hand side in arrow function parameters (2:11);

(using prettier 1.44)

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!scope:dependencyIssues that cannot be solved inside Prettier itself, and must be fixed in a dependency

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions