Properly respect associativity when reformatting (#7486)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
@ -3005,6 +3005,8 @@ impl BinaryOperator {
|
||||
}
|
||||
}
|
||||
|
||||
/// The operator associativity of the operator (as in the parsing sense, not the mathematical sense of associativity).
|
||||
///
|
||||
/// Follow JS definitions of each operator.
|
||||
/// Taken from <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_precedence#table>
|
||||
pub fn associativity(&self) -> Associativity {
|
||||
@ -3015,6 +3017,12 @@ impl BinaryOperator {
|
||||
Self::And | Self::Or => Associativity::Left,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether an operator is mathematically associative. If it is, then the operator associativity (given by the
|
||||
/// `associativity` method) is mostly irrelevant.
|
||||
pub fn associative(&self) -> bool {
|
||||
matches!(self, Self::Add | Self::Mul | Self::And | Self::Or)
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, ts_rs::TS, JsonSchema)]
|
||||
#[ts(export)]
|
||||
|
Reference in New Issue
Block a user