Skip to content

Pipe (|) operator has incorrect precedence (too tight) #27415

@thorn0

Description

@thorn0

🐞 bug report

Affected Package

The issue is caused by package @angular/core

Is this a regression?

Yes, the previous version in which this bug was not present was: 1.x

Description

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

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

It is unexpected. E.g. see #19657, prettier/prettier#5586.

Who would write a ? b : c | x meaning a ? b : (c | x) given that a ? b | x : c even is not a valid expression? This does not look like an intentional design decision, more like a mistake (bug).

The natural expectation is that the pipe in the end of an expression should be applied to the whole expression, even if there is no parentheses. According to the docs, pipes are a way to write display-value transformations that you can declare in your HTML. They are perceived as external to expressions, something that modifies the expression without really being part of it. For this intuition to be valid, pipes must have the lowest precedence. The current behavior breaks the intuition for no reason, without adding any value.

🔬 Minimal Reproduction

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions