Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(syntax): add AssignmentOperator::to_logical_operator and to_binary_operator methods #7350

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions crates/oxc_syntax/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,35 @@ impl AssignmentOperator {
)
}

/// Get [`LogicalOperator`] corresponding to this [`AssignmentOperator`].
pub fn to_logical_operator(self) -> Option<LogicalOperator> {
match self {
Self::LogicalAnd => Some(LogicalOperator::And),
Self::LogicalOr => Some(LogicalOperator::Or),
Self::LogicalNullish => Some(LogicalOperator::Coalesce),
_ => None,
}
}

/// Get [`BinaryOperator`] corresponding to this [`AssignmentOperator`].
pub fn to_binary_operator(self) -> Option<BinaryOperator> {
match self {
Self::Addition => Some(BinaryOperator::Addition),
Self::Subtraction => Some(BinaryOperator::Subtraction),
Self::Multiplication => Some(BinaryOperator::Multiplication),
Self::Division => Some(BinaryOperator::Division),
Self::Remainder => Some(BinaryOperator::Remainder),
Self::ShiftLeft => Some(BinaryOperator::ShiftLeft),
Self::ShiftRight => Some(BinaryOperator::ShiftRight),
Self::ShiftRightZeroFill => Some(BinaryOperator::ShiftRightZeroFill),
Self::BitwiseOR => Some(BinaryOperator::BitwiseOR),
Self::BitwiseXOR => Some(BinaryOperator::BitwiseXOR),
Self::BitwiseAnd => Some(BinaryOperator::BitwiseAnd),
Self::Exponential => Some(BinaryOperator::Exponential),
_ => None,
}
}

/// Get the string representation of this operator.
///
/// This is the same as how the operator appears in source code.
Expand Down
Loading