Skip to content

angular vs angularjs: operator priority problem with ?: (ternary) and | (pipe) #5586

@thorn0

Description

@thorn0

Prettier 1.15.3
Playground link

--parser angular

Input:

<div title="{{ $ctrl.collapsed ? 'Expand' : 'Collapse' | resource }}"></div>
<div [title]="$ctrl.collapsed ? 'Expand' : 'Collapse' | resource"></div>

Output:

<div title="{{ $ctrl.collapsed ? 'Expand' : ('Collapse' | resource) }}"></div>
<div [title]="$ctrl.collapsed ? 'Expand' : ('Collapse' | resource)"></div>

Expected behavior:

Same as input.

UPD

Turns out it is a grammar difference between AngularJS and Angular.

In AngularJS, a ? b : c | x means (a ? b : c) | x.

In Angular, a ? b : c | x means a ? b : (c | x).

It would make sense if Prettier kept such expressions as is to stay compatible with both. Now, it corrupts AngularJS templates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:angularIssues affecting Angular template (not general JS/TS issues used for Angular)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions