Skip to content

Improve template literal expression print in embeded language #18369

@fisker

Description

@fisker

Prettier 3.7.2
Playground link

--parser babel
--arrow-parens avoid
--trailing-comma none

Input:

const a = `flex-direction: ${long_condlong_condlong_condlong_cond ? "column-reverse" : "column"}`


const b = css`
.class{
	flex-direction: column${long_cond && long_cond && long_cond ? "-reverse" : ""};
}
`

const c = html`
	<div>${long_cond && long_cond && long_cond && long_cond && long_cond ? "-reverse" : ""}</div>
`

Output:

const a = `flex-direction: ${long_condlong_condlong_condlong_cond ? "column-reverse" : "column"}`;

const b = css`
  .class {
    flex-direction: column${long_cond && long_cond && long_cond
        ? "-reverse"
        : ""};
  }
`;

const c = html`
  <div>
    ${long_cond && long_cond && long_cond && long_cond && long_cond
      ? "-reverse"
      : ""}
  </div>
`;

Expected output:

const a = `flex-direction: ${long_condlong_condlong_condlong_cond ? "column-reverse" : "column"}`;

const b = css`
  .class {
    flex-direction: column${long_cond && long_cond && long_cond ? "-reverse" : ""};
  }
`;

const c = html`
  <div>
    ${long_cond && long_cond && long_cond && long_cond && long_cond ? "-reverse": ""}
  </div>
`;

Why?

Should not break the ternay like it's in js.

Original issue #5886

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:multiparserIssues with printing one language inside another, like CSS-in-JSlang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions