prettier/prettier
在 GitHub 查看Embedded template-literal formatting is not idempotent for nested `.map()` inside a ternary (regression in 3.9.0)
Open
#19,518 建立於 2026年7月1日
area:idempotencyhelp wantedlang:javascript
倉庫指標
- Star
- (51,868 star)
- PR 合併指標
- (平均合併 6天) (30 天內合併 186 個 PR)
描述
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.)