Unexpected embedded formatting for Angular template · Issue #15969 · prettier/prettier · GitHub
Skip to content

Unexpected embedded formatting for Angular template #15969

Closed

Description

@sosukesuzuki

Prettier 3.2.4
Playground link

--parser babel

Input:

const template = "foobar";

@Component({
  [template]: `<h1>{{       hello }}</h1>`,
})
export class AppComponent {}

Output:

const template = "foobar";

@Component({
  [template]: `<h1>{{ hello }}</h1>`,
})
export class AppComponent {}

Expected output:

const template = "foobar";

@Component({
  [template]: `<h1>{{       hello }}</h1>`,
})
export class AppComponent {}

Why?

Prettier formats the content of the template field in Angular's @Component decorator as HTML. However, it now also formats the content of a different field named template as HTML. This isn't expected.

I think adding !node.computed to

will fix this.

Activity

  1. added
    lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)
    lang:angularIssues affecting Angular template (not general JS/TS issues used for Angular)
    on Jan 21, 2024
  2. JounQin commented on Jan 21, 2024

    @JounQin
    Member

    Seems easy to fix.

  3. added 2 commits that reference this issue on Jan 22, 2024
    f0c5e51
    cd2d061
  4. JounQin commented on Jan 22, 2024

    @JounQin
    Member

    @sosukesuzuki Here you are #15972

  5. sosukesuzuki commented on Jan 23, 2024

    @sosukesuzuki
    MemberAuthor

    @JounQin Thank you for working on this!

  6. locked as resolved and limited conversation to collaborators on Apr 23, 2024
  7. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood fist issue!lang:angularIssues affecting Angular template (not general JS/TS issues used for Angular)lang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions