prettier/prettier
Voir sur GitHubEmbedded template-literal formatting is not idempotent for nested `.map()` inside a ternary (regression in 3.9.0)
Open
#19 518 ouverte le 1 juil. 2026
area:idempotencyhelp wantedlang:javascript
Métriques du dépôt
- Stars
- (51 868 stars)
- Métriques de merge PR
- (Merge moyen 6j) (186 PRs mergées en 30 j)
Description
1st pass
Prettier v3.9.4 Playground link
--parser babel
Input:
const t = html`
<ol>
${items.map(
(entry) => html`
<li>
${entry.children
? html`
<ol>
${entry.children.map(
(child) => html`<li>${child.title}</li>`,
)}
</ol>
`
: entry.title}
</li>
`,
)}
</ol>
`;
Output:
const t = html`
<ol>
${items.map(
(entry) => html`
<li>
${
entry.children
? html`
<ol>
${entry.children.map(
(child) => html`<li>${child.title}</li>`,
)}
</ol>
`
: entry.title
}
</li>
`,
)}
</ol>
`;
Diff: https://www.diffchecker.com/TRI5AAxf/
2nd pass
Prettier v3.9.4 Playground link
--parser babel
Input:
const t = html`
<ol>
${items.map(
(entry) => html`
<li>
${
entry.children
? html`
<ol>
${entry.children.map(
(child) => html`<li>${child.title}</li>`,
)}
</ol>
`
: entry.title
}
</li>
`,
)}
</ol>
`;
Output:
const t = html`
<ol>
${items.map(
(entry) => html`
<li>
${
entry.children
? html`
<ol>
${entry.children.map(
(child) => html`<li>${child.title}</li>`,
)}
</ol>
`
: entry.title
}
</li>
`,
)}
</ol>
`;
Diff: https://www.diffchecker.com/ciW9nQQn/
Expected output: to be idempotent
Instead, output stabilizes only from the 3rd pass.
Why?
Running first prettier -w and then prettier -c on any file should succeed.
(Noticed via https://github.com/mdn/fred/pull/1686.)