formatting fails on `html` template strings with interpolated element tags
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 52.3k
- Forks
- 5k
- Avg merge
- 19h 2m
- Merged PRs (30d)
- 117
Description
When using interpolations for html element names, formatting is not longer working.
I believe this used to work before, and this is a regression.
Prettier 3.6.2
Input:
const template = () => html`
<${For} each=${() => this.items}>
${() => this.content}
</${For}>
`
const template2 = () => html`
<${For} each=${() => this.items}>
${() => this.content}
</>
`
Output:
const template = () => html`
<${For} each=${() => this.items}>
${() => this.content}
</${For}>
`;
const template2 = () => html`
<${For} each=${() => this.items}>
${() => this.content}
</>
`;
Expected output:
const template = () => html`
<${For} each=${() => this.items}>
${() => this.content}
</${For}>
`;
const template2 = () => html`
<${For} each=${() => this.items}>
${() => this.content}
</>
`;
Why?
Interpolations at element tag name sites is a thing in frameworks that support function-based component references (f.e. Solid.js html).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue from the linked Prettier Playground example and trace how interpolated element names are handled while formatting JavaScript HTML template strings. Done means both examples produce the expected indentation and a regression test covers the interpolated opening and closing tags.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- html, javascript
- Domain
- frontend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100