ES pipe operator (2021) (original) (raw)
A PipeBody must not be an unparenthesized AssignmentExpression, such as YieldExpression, ArrowFunction, or ConditionalExpression—unless it is a ShortCircuitExpression.
This is to prevent confusing expressions from being valid, such as:
x |> yield % |> % + 1 // Syntax Error
This expression would otherwise be equivalent to:
x |> (yield % |> % + 1)
Likewise, this expression:
x |> y ? % : z |> % + 1 // Syntax Error
…would otherwise be equivalent to:
x |> (y ? % : z |> % + 1)
These expressions are visually unclear and are therefore made invalid. The developer may make them valid with explicit parentheses:
x |> (yield %) |> % + 1
x |> (yield % |> % + 1)
x |> (y ? % : z) |> % + 1
x |> (y ? % : z |> % + 1)