Skip to content

Prettier respects template literals, but not tagged templates #3670

@btraut

Description

@btraut

As far as I can tell, it's prettier's philosophy to leave template literals unaffected (except for breaking on the tokens) because adding breaks and indentation actually modifies the code. This tends to work fine, but it breaks when it comes to tagged templates, the syntax where you call a function with a template literal and leave off the parens.

A simple fix in my code was to add the parens back in to the function call, but this won't work for everyone as it actually changes the arguments for the resulting function call.

Prettier 1.9.2
Playground link

Input:

md`
This line shouldn't be indented at all in the resulting output, but it is.
`

md(`
Prettier does the right thing on this line and preserves the indentation level.
`)

Output:

md`
  This line shouldn't be indented at all in the resulting output, but it is.
`;

md(`
Prettier does the right thing on this line and preserves the indentation level.
`)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:multiparserIssues with printing one language inside another, like CSS-in-JSlang:javascriptIssues affecting JSlang:markdownIssues affecting Markdownlocked-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

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions