Skip to content

Angular parser breaks ngClass construct #5367

@spitfjre

Description

@spitfjre

Tried out the new angular parser. After formatting our very large code base. I stumbled over this, because formatting this with prettier produced different results in different iterations.

Prettier 1.15.1

Input:

<button
  type="button"
  (click)="closeDialog()"
  class="btn btn-primary"
  [ngClass]="{
    'btn-success': (dialog$ | async).level === dialogLevelEnum.SUCCESS,
    'btn-warning': (dialog$ | async).level === dialogLevelEnum.WARNING,
    'btn-svg': (dialog$ | async).level === dialogLevelEnum.DANGER
  }">
  {{(dialog$ | async).btnTxt}}
</button>

Output (1st iteration):

<button
  type="button"
  (click)="closeDialog()"
  class="btn btn-primary"
  [ngClass]="{
    '-success\': ': (dialog$ | async).level === dialogLevelEnum.SUCCESS,
    '-warning\': ': (dialog$ | async).level === dialogLevelEnum.WARNING,
    '-svg\': ': (dialog$ | async).level === dialogLevelEnum.DANGER
  }"
>
  {{ (dialog$ | async).btnTxt }}
</button>

Output (2nd iteration):

<button
  type="button"
  (click)="closeDialog()"
  class="btn btn-primary"
  [ngClass]="{
    'cess\': \': ': (dialog$ | async).level === dialogLevelEnum.SUCCESS,
    'ning\': \': ': (dialog$ | async).level === dialogLevelEnum.WARNING,
    '\': \': ': (dialog$ | async).level === dialogLevelEnum.DANGER
  }"
>
  {{ (dialog$ | async).btnTxt }}
</button>

Output (3rd iteration):

<button
  type="button"
  (click)="closeDialog()"
  class="btn btn-primary"
  [ngClass]="{
    '\': \': \': ': (dialog$ | async).level === dialogLevelEnum.SUCCESS,
    '\': \': \': ': (dialog$ | async).level === dialogLevelEnum.WARNING,
    '\': \': ': (dialog$ | async).level === dialogLevelEnum.DANGER
  }"
>
  {{ (dialog$ | async).btnTxt }}
</button>

Output (4th iteration):

<button
  type="button"
  (click)="closeDialog()"
  class="btn btn-primary"
  [ngClass]="{
    ': \': \': ': (dialog$ | async).level === dialogLevelEnum.SUCCESS,
    ': \': \': ': (dialog$ | async).level === dialogLevelEnum.WARNING,
    '\': \': ': (dialog$ | async).level === dialogLevelEnum.DANGER
  }"
>
  {{ (dialog$ | async).btnTxt }}
</button>

Output (5th iteration):

<button
  type="button"
  (click)="closeDialog()"
  class="btn btn-primary"
  [ngClass]="{
    ' \': \': ': (dialog$ | async).level === dialogLevelEnum.SUCCESS,
    ' \': \': ': (dialog$ | async).level === dialogLevelEnum.WARNING,
    '\': \': ': (dialog$ | async).level === dialogLevelEnum.DANGER
  }"
>
  {{ (dialog$ | async).btnTxt }}
</button>

Output (6th iteration - stable from now on):

<button
  type="button"
  (click)="closeDialog()"
  class="btn btn-primary"
  [ngClass]="{
    '\': \': ': (dialog$ | async).level === dialogLevelEnum.SUCCESS,
    '\': \': ': (dialog$ | async).level === dialogLevelEnum.WARNING,
    '\': \': ': (dialog$ | async).level === dialogLevelEnum.DANGER
  }"
>
  {{ (dialog$ | async).btnTxt }}
</button>

Expected behavior:
Not to break code.

Metadata

Metadata

Assignees

Labels

lang:angularIssues affecting Angular template (not general JS/TS issues used for Angular)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!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