prettier / prettier/prettier

formatting fails on `html` template strings with interpolated element tags

Open
#17,849 1 comment 0 reactions 0 assignees View on GitHub

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

Playground link

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.