Fix HTML attribute name normalization (#19709)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-07-25 08:08:13 +08:00
1 parent 7c5872f7a2
commit bfb1eacd89
5 files changed
+99 -3

No files matched your search

@@ -0,0 +1,38 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`snippet: #0 format 1`] = `
====================================options=====================================
parsers: ["html"]
printWidth: 80 (default) |
=====================================input======================================
<div
CLASS="should print as lowercase"
UNKNOWN="should print as UPPERCASE"
>
Tag with attributes
</div>
<span
CLASS="should print as lowercase"
UNKNOWN="should print as UPPERCASE"
>
Tag without attributes
</span>
<unknown
CLASS="should print as UPPERCASE"
UNKNOWN="should print as UPPERCASE"
>
Non-html element
</unknown>
=====================================output=====================================
<div class="should print as lowercase" UNKNOWN="should print as UPPERCASE">
Tag with attributes
</div>
<span class="should print as lowercase" UNKNOWN="should print as UPPERCASE">
Tag without attributes
</span>
<unknown CLASS="should print as UPPERCASE" UNKNOWN="should print as UPPERCASE">
Non-html element
</unknown>
================================================================================
`;
@@ -0,0 +1,39 @@
import { elementAttributes } from "@prettier/html-attributes";
import { htmlTags } from "@prettier/html-tags";
import { outdent } from "outdent";
const tagWithAttribute = elementAttributes.div
? "div"
: htmlTags.find((tag) => elementAttributes[tag]);
const tagWithoutAttribute = !elementAttributes.span
? "span"
: htmlTags.find((tag) => !elementAttributes[tag]);
runFormatTest(
{
importMeta: import.meta,
snippets: [
outdent`
<${tagWithAttribute}
CLASS="should print as lowercase"
UNKNOWN="should print as UPPERCASE"
>
Tag with attributes
</${tagWithAttribute}>
<${tagWithoutAttribute}
CLASS="should print as lowercase"
UNKNOWN="should print as UPPERCASE"
>
Tag without attributes
</${tagWithoutAttribute}>
<unknown
CLASS="should print as UPPERCASE"
UNKNOWN="should print as UPPERCASE"
>
Non-html element
</unknown>
`,
],
},
["html"],
);