Skip to content

js in html tagged template literals too verbose? #5672

@daKmoR

Description

@daKmoR

hey,

so when using prettier for tagged template literals it becomes kind of very verbose. e.g. it puts every ${ and function() on its own line. I would like to get easily readable and "short" js/html code - and that in this case unneeded verbosity sort of defeats the purpose.

Don't get me wrong for javascript it completely makes sense... but the js in a html tagged template literal is usually pretty limited. e.g. you will not define full functions there.

So this is basically a discussion to see if we can get a more "suitable" default for js in html tagged template literals. It does not need to be completely the same as Expected behavior but not putting each ${ followed by a function onto a seprate line would already help tremendously.

Prettier 1.15.3
Playground link

--parser babylon

Input:

const bars = ['end of the earth', 'drunken sailors'];

function HelloWorld() {
  return html`
    <h3>Bar List</h3>
    ${bars.map(bar => html`
       <p>${bar}</p>
    `)}
  `;
}

Output:

const bars = ["end of the earth", "drunken sailors"];

function HelloWorld() {
  return html`
    <h3>Bar List</h3>
    ${
      bars.map(
        bar => html`
          <p>${bar}</p>
        `
      )
    }
  `;
}

Expected behavior:

const bars = ["end of the earth", "drunken sailors"];

function HelloWorld() {
  return html`
    <h3>Bar List</h3>
    ${bars.map(bar => html`
       <p>${bar}</p>
    `)}
  `;
}

An alternative possible outcome (okish):

const bars = ["end of the earth", "drunken sailors"];

function HelloWorld() {
  return html`
    <h3>Bar List</h3>
    ${bars.map(
       bar => html`
         <p>${bar}</p>
       `
    )}
  `;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:multiparserIssues with printing one language inside another, like CSS-in-JSlang:htmlIssues affecting HTML (and SVG but not JSX)lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:has prIssues with an accompanying pull request. These issues will probably be fixed soon!

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions