mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
perf(syntax): reorder operator enum variants (#7351)
Re-order enum variants of `AssignmentOperator`, `BinaryOperator` and `UnaryOperator`. * `Exponential` moved to after `Remainder` (so with the rest of the arithmetic operators). * `Shift*` operators follow arithmetic operators. * `AssignmentOperator::Bitwise*` ops moved to before `Logical*` ops (so all ops which correspond to `BinaryOperator`s are together). * `*Or` always before `*And`. * Plus/Addition always before Minus/Subtraction. The purpose is to make the various methods on these types maximally efficient: 1. Group together variants so that `AssignmentOperator::is_*` methods can be executed with the minimum number of operations (essentially `variant - min <= max`). 2. Align the variants of `AssignmentOperator` and `BinaryOperator` so that conversion methods added in #7350 become very cheap too (essentially `if variant - min <= max { Some(variant + offset) } else { None }`).
This commit is contained in:
parent
bc0e72c1e2
commit
c335f92ada
4 changed files with 125 additions and 125 deletions
|
|
@ -44,16 +44,16 @@ impl<'alloc> CloneIn<'alloc> for AssignmentOperator {
|
||||||
Self::Multiplication => AssignmentOperator::Multiplication,
|
Self::Multiplication => AssignmentOperator::Multiplication,
|
||||||
Self::Division => AssignmentOperator::Division,
|
Self::Division => AssignmentOperator::Division,
|
||||||
Self::Remainder => AssignmentOperator::Remainder,
|
Self::Remainder => AssignmentOperator::Remainder,
|
||||||
|
Self::Exponential => AssignmentOperator::Exponential,
|
||||||
Self::ShiftLeft => AssignmentOperator::ShiftLeft,
|
Self::ShiftLeft => AssignmentOperator::ShiftLeft,
|
||||||
Self::ShiftRight => AssignmentOperator::ShiftRight,
|
Self::ShiftRight => AssignmentOperator::ShiftRight,
|
||||||
Self::ShiftRightZeroFill => AssignmentOperator::ShiftRightZeroFill,
|
Self::ShiftRightZeroFill => AssignmentOperator::ShiftRightZeroFill,
|
||||||
Self::BitwiseOR => AssignmentOperator::BitwiseOR,
|
Self::BitwiseOR => AssignmentOperator::BitwiseOR,
|
||||||
Self::BitwiseXOR => AssignmentOperator::BitwiseXOR,
|
Self::BitwiseXOR => AssignmentOperator::BitwiseXOR,
|
||||||
Self::BitwiseAnd => AssignmentOperator::BitwiseAnd,
|
Self::BitwiseAnd => AssignmentOperator::BitwiseAnd,
|
||||||
Self::LogicalAnd => AssignmentOperator::LogicalAnd,
|
|
||||||
Self::LogicalOr => AssignmentOperator::LogicalOr,
|
Self::LogicalOr => AssignmentOperator::LogicalOr,
|
||||||
|
Self::LogicalAnd => AssignmentOperator::LogicalAnd,
|
||||||
Self::LogicalNullish => AssignmentOperator::LogicalNullish,
|
Self::LogicalNullish => AssignmentOperator::LogicalNullish,
|
||||||
Self::Exponential => AssignmentOperator::Exponential,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -70,20 +70,20 @@ impl<'alloc> CloneIn<'alloc> for BinaryOperator {
|
||||||
Self::LessEqualThan => BinaryOperator::LessEqualThan,
|
Self::LessEqualThan => BinaryOperator::LessEqualThan,
|
||||||
Self::GreaterThan => BinaryOperator::GreaterThan,
|
Self::GreaterThan => BinaryOperator::GreaterThan,
|
||||||
Self::GreaterEqualThan => BinaryOperator::GreaterEqualThan,
|
Self::GreaterEqualThan => BinaryOperator::GreaterEqualThan,
|
||||||
Self::ShiftLeft => BinaryOperator::ShiftLeft,
|
|
||||||
Self::ShiftRight => BinaryOperator::ShiftRight,
|
|
||||||
Self::ShiftRightZeroFill => BinaryOperator::ShiftRightZeroFill,
|
|
||||||
Self::Addition => BinaryOperator::Addition,
|
Self::Addition => BinaryOperator::Addition,
|
||||||
Self::Subtraction => BinaryOperator::Subtraction,
|
Self::Subtraction => BinaryOperator::Subtraction,
|
||||||
Self::Multiplication => BinaryOperator::Multiplication,
|
Self::Multiplication => BinaryOperator::Multiplication,
|
||||||
Self::Division => BinaryOperator::Division,
|
Self::Division => BinaryOperator::Division,
|
||||||
Self::Remainder => BinaryOperator::Remainder,
|
Self::Remainder => BinaryOperator::Remainder,
|
||||||
|
Self::Exponential => BinaryOperator::Exponential,
|
||||||
|
Self::ShiftLeft => BinaryOperator::ShiftLeft,
|
||||||
|
Self::ShiftRight => BinaryOperator::ShiftRight,
|
||||||
|
Self::ShiftRightZeroFill => BinaryOperator::ShiftRightZeroFill,
|
||||||
Self::BitwiseOR => BinaryOperator::BitwiseOR,
|
Self::BitwiseOR => BinaryOperator::BitwiseOR,
|
||||||
Self::BitwiseXOR => BinaryOperator::BitwiseXOR,
|
Self::BitwiseXOR => BinaryOperator::BitwiseXOR,
|
||||||
Self::BitwiseAnd => BinaryOperator::BitwiseAnd,
|
Self::BitwiseAnd => BinaryOperator::BitwiseAnd,
|
||||||
Self::In => BinaryOperator::In,
|
Self::In => BinaryOperator::In,
|
||||||
Self::Instanceof => BinaryOperator::Instanceof,
|
Self::Instanceof => BinaryOperator::Instanceof,
|
||||||
Self::Exponential => BinaryOperator::Exponential,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -103,8 +103,8 @@ impl<'alloc> CloneIn<'alloc> for UnaryOperator {
|
||||||
type Cloned = UnaryOperator;
|
type Cloned = UnaryOperator;
|
||||||
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
|
||||||
match self {
|
match self {
|
||||||
Self::UnaryNegation => UnaryOperator::UnaryNegation,
|
|
||||||
Self::UnaryPlus => UnaryOperator::UnaryPlus,
|
Self::UnaryPlus => UnaryOperator::UnaryPlus,
|
||||||
|
Self::UnaryNegation => UnaryOperator::UnaryNegation,
|
||||||
Self::LogicalNot => UnaryOperator::LogicalNot,
|
Self::LogicalNot => UnaryOperator::LogicalNot,
|
||||||
Self::BitwiseNot => UnaryOperator::BitwiseNot,
|
Self::BitwiseNot => UnaryOperator::BitwiseNot,
|
||||||
Self::Typeof => UnaryOperator::Typeof,
|
Self::Typeof => UnaryOperator::Typeof,
|
||||||
|
|
|
||||||
|
|
@ -28,35 +28,35 @@ impl Serialize for AssignmentOperator {
|
||||||
AssignmentOperator::Remainder => {
|
AssignmentOperator::Remainder => {
|
||||||
serializer.serialize_unit_variant("AssignmentOperator", 5u32, "%=")
|
serializer.serialize_unit_variant("AssignmentOperator", 5u32, "%=")
|
||||||
}
|
}
|
||||||
|
AssignmentOperator::Exponential => {
|
||||||
|
serializer.serialize_unit_variant("AssignmentOperator", 6u32, "**=")
|
||||||
|
}
|
||||||
AssignmentOperator::ShiftLeft => {
|
AssignmentOperator::ShiftLeft => {
|
||||||
serializer.serialize_unit_variant("AssignmentOperator", 6u32, "<<=")
|
serializer.serialize_unit_variant("AssignmentOperator", 7u32, "<<=")
|
||||||
}
|
}
|
||||||
AssignmentOperator::ShiftRight => {
|
AssignmentOperator::ShiftRight => {
|
||||||
serializer.serialize_unit_variant("AssignmentOperator", 7u32, ">>=")
|
serializer.serialize_unit_variant("AssignmentOperator", 8u32, ">>=")
|
||||||
}
|
}
|
||||||
AssignmentOperator::ShiftRightZeroFill => {
|
AssignmentOperator::ShiftRightZeroFill => {
|
||||||
serializer.serialize_unit_variant("AssignmentOperator", 8u32, ">>>=")
|
serializer.serialize_unit_variant("AssignmentOperator", 9u32, ">>>=")
|
||||||
}
|
}
|
||||||
AssignmentOperator::BitwiseOR => {
|
AssignmentOperator::BitwiseOR => {
|
||||||
serializer.serialize_unit_variant("AssignmentOperator", 9u32, "|=")
|
serializer.serialize_unit_variant("AssignmentOperator", 10u32, "|=")
|
||||||
}
|
}
|
||||||
AssignmentOperator::BitwiseXOR => {
|
AssignmentOperator::BitwiseXOR => {
|
||||||
serializer.serialize_unit_variant("AssignmentOperator", 10u32, "^=")
|
serializer.serialize_unit_variant("AssignmentOperator", 11u32, "^=")
|
||||||
}
|
}
|
||||||
AssignmentOperator::BitwiseAnd => {
|
AssignmentOperator::BitwiseAnd => {
|
||||||
serializer.serialize_unit_variant("AssignmentOperator", 11u32, "&=")
|
serializer.serialize_unit_variant("AssignmentOperator", 12u32, "&=")
|
||||||
}
|
|
||||||
AssignmentOperator::LogicalAnd => {
|
|
||||||
serializer.serialize_unit_variant("AssignmentOperator", 12u32, "&&=")
|
|
||||||
}
|
}
|
||||||
AssignmentOperator::LogicalOr => {
|
AssignmentOperator::LogicalOr => {
|
||||||
serializer.serialize_unit_variant("AssignmentOperator", 13u32, "||=")
|
serializer.serialize_unit_variant("AssignmentOperator", 13u32, "||=")
|
||||||
}
|
}
|
||||||
AssignmentOperator::LogicalNullish => {
|
AssignmentOperator::LogicalAnd => {
|
||||||
serializer.serialize_unit_variant("AssignmentOperator", 14u32, "??=")
|
serializer.serialize_unit_variant("AssignmentOperator", 14u32, "&&=")
|
||||||
}
|
}
|
||||||
AssignmentOperator::Exponential => {
|
AssignmentOperator::LogicalNullish => {
|
||||||
serializer.serialize_unit_variant("AssignmentOperator", 15u32, "**=")
|
serializer.serialize_unit_variant("AssignmentOperator", 15u32, "??=")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -89,45 +89,45 @@ impl Serialize for BinaryOperator {
|
||||||
BinaryOperator::GreaterEqualThan => {
|
BinaryOperator::GreaterEqualThan => {
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 7u32, ">=")
|
serializer.serialize_unit_variant("BinaryOperator", 7u32, ">=")
|
||||||
}
|
}
|
||||||
BinaryOperator::ShiftLeft => {
|
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 8u32, "<<")
|
|
||||||
}
|
|
||||||
BinaryOperator::ShiftRight => {
|
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 9u32, ">>")
|
|
||||||
}
|
|
||||||
BinaryOperator::ShiftRightZeroFill => {
|
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 10u32, ">>>")
|
|
||||||
}
|
|
||||||
BinaryOperator::Addition => {
|
BinaryOperator::Addition => {
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 11u32, "+")
|
serializer.serialize_unit_variant("BinaryOperator", 8u32, "+")
|
||||||
}
|
}
|
||||||
BinaryOperator::Subtraction => {
|
BinaryOperator::Subtraction => {
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 12u32, "-")
|
serializer.serialize_unit_variant("BinaryOperator", 9u32, "-")
|
||||||
}
|
}
|
||||||
BinaryOperator::Multiplication => {
|
BinaryOperator::Multiplication => {
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 13u32, "*")
|
serializer.serialize_unit_variant("BinaryOperator", 10u32, "*")
|
||||||
}
|
}
|
||||||
BinaryOperator::Division => {
|
BinaryOperator::Division => {
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 14u32, "/")
|
serializer.serialize_unit_variant("BinaryOperator", 11u32, "/")
|
||||||
}
|
}
|
||||||
BinaryOperator::Remainder => {
|
BinaryOperator::Remainder => {
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 15u32, "%")
|
serializer.serialize_unit_variant("BinaryOperator", 12u32, "%")
|
||||||
}
|
|
||||||
BinaryOperator::BitwiseOR => {
|
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 16u32, "|")
|
|
||||||
}
|
|
||||||
BinaryOperator::BitwiseXOR => {
|
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 17u32, "^")
|
|
||||||
}
|
|
||||||
BinaryOperator::BitwiseAnd => {
|
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 18u32, "&")
|
|
||||||
}
|
|
||||||
BinaryOperator::In => serializer.serialize_unit_variant("BinaryOperator", 19u32, "in"),
|
|
||||||
BinaryOperator::Instanceof => {
|
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 20u32, "instanceof")
|
|
||||||
}
|
}
|
||||||
BinaryOperator::Exponential => {
|
BinaryOperator::Exponential => {
|
||||||
serializer.serialize_unit_variant("BinaryOperator", 21u32, "**")
|
serializer.serialize_unit_variant("BinaryOperator", 13u32, "**")
|
||||||
|
}
|
||||||
|
BinaryOperator::ShiftLeft => {
|
||||||
|
serializer.serialize_unit_variant("BinaryOperator", 14u32, "<<")
|
||||||
|
}
|
||||||
|
BinaryOperator::ShiftRight => {
|
||||||
|
serializer.serialize_unit_variant("BinaryOperator", 15u32, ">>")
|
||||||
|
}
|
||||||
|
BinaryOperator::ShiftRightZeroFill => {
|
||||||
|
serializer.serialize_unit_variant("BinaryOperator", 16u32, ">>>")
|
||||||
|
}
|
||||||
|
BinaryOperator::BitwiseOR => {
|
||||||
|
serializer.serialize_unit_variant("BinaryOperator", 17u32, "|")
|
||||||
|
}
|
||||||
|
BinaryOperator::BitwiseXOR => {
|
||||||
|
serializer.serialize_unit_variant("BinaryOperator", 18u32, "^")
|
||||||
|
}
|
||||||
|
BinaryOperator::BitwiseAnd => {
|
||||||
|
serializer.serialize_unit_variant("BinaryOperator", 19u32, "&")
|
||||||
|
}
|
||||||
|
BinaryOperator::In => serializer.serialize_unit_variant("BinaryOperator", 20u32, "in"),
|
||||||
|
BinaryOperator::Instanceof => {
|
||||||
|
serializer.serialize_unit_variant("BinaryOperator", 21u32, "instanceof")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -150,11 +150,11 @@ impl Serialize for LogicalOperator {
|
||||||
impl Serialize for UnaryOperator {
|
impl Serialize for UnaryOperator {
|
||||||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||||
match *self {
|
match *self {
|
||||||
UnaryOperator::UnaryNegation => {
|
|
||||||
serializer.serialize_unit_variant("UnaryOperator", 0u32, "-")
|
|
||||||
}
|
|
||||||
UnaryOperator::UnaryPlus => {
|
UnaryOperator::UnaryPlus => {
|
||||||
serializer.serialize_unit_variant("UnaryOperator", 1u32, "+")
|
serializer.serialize_unit_variant("UnaryOperator", 0u32, "+")
|
||||||
|
}
|
||||||
|
UnaryOperator::UnaryNegation => {
|
||||||
|
serializer.serialize_unit_variant("UnaryOperator", 1u32, "-")
|
||||||
}
|
}
|
||||||
UnaryOperator::LogicalNot => {
|
UnaryOperator::LogicalNot => {
|
||||||
serializer.serialize_unit_variant("UnaryOperator", 2u32, "!")
|
serializer.serialize_unit_variant("UnaryOperator", 2u32, "!")
|
||||||
|
|
|
||||||
|
|
@ -37,42 +37,42 @@ pub enum AssignmentOperator {
|
||||||
/// `%=`
|
/// `%=`
|
||||||
#[estree(rename = "%=")]
|
#[estree(rename = "%=")]
|
||||||
Remainder = 5,
|
Remainder = 5,
|
||||||
|
/// `**=`
|
||||||
|
#[estree(rename = "**=")]
|
||||||
|
Exponential = 6,
|
||||||
/// `<<=`
|
/// `<<=`
|
||||||
#[estree(rename = "<<=")]
|
#[estree(rename = "<<=")]
|
||||||
ShiftLeft = 6,
|
ShiftLeft = 7,
|
||||||
/// `>>=`
|
/// `>>=`
|
||||||
#[estree(rename = ">>=")]
|
#[estree(rename = ">>=")]
|
||||||
ShiftRight = 7,
|
ShiftRight = 8,
|
||||||
/// `>>>=`
|
/// `>>>=`
|
||||||
#[estree(rename = ">>>=")]
|
#[estree(rename = ">>>=")]
|
||||||
ShiftRightZeroFill = 8,
|
ShiftRightZeroFill = 9,
|
||||||
/// `|=`
|
/// `|=`
|
||||||
#[estree(rename = "|=")]
|
#[estree(rename = "|=")]
|
||||||
BitwiseOR = 9,
|
BitwiseOR = 10,
|
||||||
/// `^=`
|
/// `^=`
|
||||||
#[estree(rename = "^=")]
|
#[estree(rename = "^=")]
|
||||||
BitwiseXOR = 10,
|
BitwiseXOR = 11,
|
||||||
/// `&=`
|
/// `&=`
|
||||||
#[estree(rename = "&=")]
|
#[estree(rename = "&=")]
|
||||||
BitwiseAnd = 11,
|
BitwiseAnd = 12,
|
||||||
/// `&&=`
|
|
||||||
#[estree(rename = "&&=")]
|
|
||||||
LogicalAnd = 12,
|
|
||||||
/// `||=`
|
/// `||=`
|
||||||
#[estree(rename = "||=")]
|
#[estree(rename = "||=")]
|
||||||
LogicalOr = 13,
|
LogicalOr = 13,
|
||||||
|
/// `&&=`
|
||||||
|
#[estree(rename = "&&=")]
|
||||||
|
LogicalAnd = 14,
|
||||||
/// `??=`
|
/// `??=`
|
||||||
#[estree(rename = "??=")]
|
#[estree(rename = "??=")]
|
||||||
LogicalNullish = 14,
|
LogicalNullish = 15,
|
||||||
/// `**=`
|
|
||||||
#[estree(rename = "**=")]
|
|
||||||
Exponential = 15,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AssignmentOperator {
|
impl AssignmentOperator {
|
||||||
/// Returns `true` for '||=`, `&&=`, and `??=`.
|
/// Returns `true` for '||=`, `&&=`, and `??=`.
|
||||||
pub fn is_logical(self) -> bool {
|
pub fn is_logical(self) -> bool {
|
||||||
matches!(self, Self::LogicalAnd | Self::LogicalOr | Self::LogicalNullish)
|
matches!(self, Self::LogicalOr | Self::LogicalAnd | Self::LogicalNullish)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` for `+=`, `-=`, `*=`, `/=`, `%=`, and `**=`.
|
/// Returns `true` for `+=`, `-=`, `*=`, `/=`, `%=`, and `**=`.
|
||||||
|
|
@ -90,16 +90,16 @@ impl AssignmentOperator {
|
||||||
pub fn is_bitwise(self) -> bool {
|
pub fn is_bitwise(self) -> bool {
|
||||||
matches!(
|
matches!(
|
||||||
self,
|
self,
|
||||||
Self::BitwiseOR | Self::BitwiseXOR | Self::BitwiseAnd
|
Self::ShiftLeft | Self::ShiftRight | Self::ShiftRightZeroFill
|
||||||
| Self::ShiftLeft | Self::ShiftRight | Self::ShiftRightZeroFill
|
| Self::BitwiseOR | Self::BitwiseXOR | Self::BitwiseAnd
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get [`LogicalOperator`] corresponding to this [`AssignmentOperator`].
|
/// Get [`LogicalOperator`] corresponding to this [`AssignmentOperator`].
|
||||||
pub fn to_logical_operator(self) -> Option<LogicalOperator> {
|
pub fn to_logical_operator(self) -> Option<LogicalOperator> {
|
||||||
match self {
|
match self {
|
||||||
Self::LogicalAnd => Some(LogicalOperator::And),
|
|
||||||
Self::LogicalOr => Some(LogicalOperator::Or),
|
Self::LogicalOr => Some(LogicalOperator::Or),
|
||||||
|
Self::LogicalAnd => Some(LogicalOperator::And),
|
||||||
Self::LogicalNullish => Some(LogicalOperator::Coalesce),
|
Self::LogicalNullish => Some(LogicalOperator::Coalesce),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
@ -113,13 +113,13 @@ impl AssignmentOperator {
|
||||||
Self::Multiplication => Some(BinaryOperator::Multiplication),
|
Self::Multiplication => Some(BinaryOperator::Multiplication),
|
||||||
Self::Division => Some(BinaryOperator::Division),
|
Self::Division => Some(BinaryOperator::Division),
|
||||||
Self::Remainder => Some(BinaryOperator::Remainder),
|
Self::Remainder => Some(BinaryOperator::Remainder),
|
||||||
|
Self::Exponential => Some(BinaryOperator::Exponential),
|
||||||
Self::ShiftLeft => Some(BinaryOperator::ShiftLeft),
|
Self::ShiftLeft => Some(BinaryOperator::ShiftLeft),
|
||||||
Self::ShiftRight => Some(BinaryOperator::ShiftRight),
|
Self::ShiftRight => Some(BinaryOperator::ShiftRight),
|
||||||
Self::ShiftRightZeroFill => Some(BinaryOperator::ShiftRightZeroFill),
|
Self::ShiftRightZeroFill => Some(BinaryOperator::ShiftRightZeroFill),
|
||||||
Self::BitwiseOR => Some(BinaryOperator::BitwiseOR),
|
Self::BitwiseOR => Some(BinaryOperator::BitwiseOR),
|
||||||
Self::BitwiseXOR => Some(BinaryOperator::BitwiseXOR),
|
Self::BitwiseXOR => Some(BinaryOperator::BitwiseXOR),
|
||||||
Self::BitwiseAnd => Some(BinaryOperator::BitwiseAnd),
|
Self::BitwiseAnd => Some(BinaryOperator::BitwiseAnd),
|
||||||
Self::Exponential => Some(BinaryOperator::Exponential),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -135,16 +135,16 @@ impl AssignmentOperator {
|
||||||
Self::Multiplication => "*=",
|
Self::Multiplication => "*=",
|
||||||
Self::Division => "/=",
|
Self::Division => "/=",
|
||||||
Self::Remainder => "%=",
|
Self::Remainder => "%=",
|
||||||
|
Self::Exponential => "**=",
|
||||||
Self::ShiftLeft => "<<=",
|
Self::ShiftLeft => "<<=",
|
||||||
Self::ShiftRight => ">>=",
|
Self::ShiftRight => ">>=",
|
||||||
Self::ShiftRightZeroFill => ">>>=",
|
Self::ShiftRightZeroFill => ">>>=",
|
||||||
Self::BitwiseOR => "|=",
|
Self::BitwiseOR => "|=",
|
||||||
Self::BitwiseXOR => "^=",
|
Self::BitwiseXOR => "^=",
|
||||||
Self::BitwiseAnd => "&=",
|
Self::BitwiseAnd => "&=",
|
||||||
Self::LogicalAnd => "&&=",
|
|
||||||
Self::LogicalOr => "||=",
|
Self::LogicalOr => "||=",
|
||||||
|
Self::LogicalAnd => "&&=",
|
||||||
Self::LogicalNullish => "??=",
|
Self::LogicalNullish => "??=",
|
||||||
Self::Exponential => "**=",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -182,48 +182,48 @@ pub enum BinaryOperator {
|
||||||
/// `>=`
|
/// `>=`
|
||||||
#[estree(rename = ">=")]
|
#[estree(rename = ">=")]
|
||||||
GreaterEqualThan = 7,
|
GreaterEqualThan = 7,
|
||||||
/// `<<`
|
|
||||||
#[estree(rename = "<<")]
|
|
||||||
ShiftLeft = 8,
|
|
||||||
/// `>>`
|
|
||||||
#[estree(rename = ">>")]
|
|
||||||
ShiftRight = 9,
|
|
||||||
/// `>>>`
|
|
||||||
#[estree(rename = ">>>")]
|
|
||||||
ShiftRightZeroFill = 10,
|
|
||||||
/// `+`
|
/// `+`
|
||||||
#[estree(rename = "+")]
|
#[estree(rename = "+")]
|
||||||
Addition = 11,
|
Addition = 8,
|
||||||
/// `-`
|
/// `-`
|
||||||
#[estree(rename = "-")]
|
#[estree(rename = "-")]
|
||||||
Subtraction = 12,
|
Subtraction = 9,
|
||||||
/// `*`
|
/// `*`
|
||||||
#[estree(rename = "*")]
|
#[estree(rename = "*")]
|
||||||
Multiplication = 13,
|
Multiplication = 10,
|
||||||
/// `/`
|
/// `/`
|
||||||
#[estree(rename = "/")]
|
#[estree(rename = "/")]
|
||||||
Division = 14,
|
Division = 11,
|
||||||
/// `%`
|
/// `%`
|
||||||
#[estree(rename = "%")]
|
#[estree(rename = "%")]
|
||||||
Remainder = 15,
|
Remainder = 12,
|
||||||
/// `|`
|
|
||||||
#[estree(rename = "|")]
|
|
||||||
BitwiseOR = 16,
|
|
||||||
/// `^`
|
|
||||||
#[estree(rename = "^")]
|
|
||||||
BitwiseXOR = 17,
|
|
||||||
/// `&`
|
|
||||||
#[estree(rename = "&")]
|
|
||||||
BitwiseAnd = 18,
|
|
||||||
/// `in`
|
|
||||||
#[estree(rename = "in")]
|
|
||||||
In = 19,
|
|
||||||
/// `instanceof`
|
|
||||||
#[estree(rename = "instanceof")]
|
|
||||||
Instanceof = 20,
|
|
||||||
/// `**`
|
/// `**`
|
||||||
#[estree(rename = "**")]
|
#[estree(rename = "**")]
|
||||||
Exponential = 21,
|
Exponential = 13,
|
||||||
|
/// `<<`
|
||||||
|
#[estree(rename = "<<")]
|
||||||
|
ShiftLeft = 14,
|
||||||
|
/// `>>`
|
||||||
|
#[estree(rename = ">>")]
|
||||||
|
ShiftRight = 15,
|
||||||
|
/// `>>>`
|
||||||
|
#[estree(rename = ">>>")]
|
||||||
|
ShiftRightZeroFill = 16,
|
||||||
|
/// `|`
|
||||||
|
#[estree(rename = "|")]
|
||||||
|
BitwiseOR = 17,
|
||||||
|
/// `^`
|
||||||
|
#[estree(rename = "^")]
|
||||||
|
BitwiseXOR = 18,
|
||||||
|
/// `&`
|
||||||
|
#[estree(rename = "&")]
|
||||||
|
BitwiseAnd = 19,
|
||||||
|
/// `in`
|
||||||
|
#[estree(rename = "in")]
|
||||||
|
In = 20,
|
||||||
|
/// `instanceof`
|
||||||
|
#[estree(rename = "instanceof")]
|
||||||
|
Instanceof = 21,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BinaryOperator {
|
impl BinaryOperator {
|
||||||
|
|
@ -262,7 +262,7 @@ impl BinaryOperator {
|
||||||
|
|
||||||
/// Returns `true` if this is an [`In`](BinaryOperator::In) operator.
|
/// Returns `true` if this is an [`In`](BinaryOperator::In) operator.
|
||||||
pub fn is_in(self) -> bool {
|
pub fn is_in(self) -> bool {
|
||||||
matches!(self, Self::In)
|
self == Self::In
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` for any bitwise operator
|
/// Returns `true` for any bitwise operator
|
||||||
|
|
@ -321,20 +321,20 @@ impl BinaryOperator {
|
||||||
Self::LessEqualThan => "<=",
|
Self::LessEqualThan => "<=",
|
||||||
Self::GreaterThan => ">",
|
Self::GreaterThan => ">",
|
||||||
Self::GreaterEqualThan => ">=",
|
Self::GreaterEqualThan => ">=",
|
||||||
Self::ShiftLeft => "<<",
|
|
||||||
Self::ShiftRight => ">>",
|
|
||||||
Self::ShiftRightZeroFill => ">>>",
|
|
||||||
Self::Addition => "+",
|
Self::Addition => "+",
|
||||||
Self::Subtraction => "-",
|
Self::Subtraction => "-",
|
||||||
Self::Multiplication => "*",
|
Self::Multiplication => "*",
|
||||||
Self::Division => "/",
|
Self::Division => "/",
|
||||||
Self::Remainder => "%",
|
Self::Remainder => "%",
|
||||||
|
Self::Exponential => "**",
|
||||||
|
Self::ShiftLeft => "<<",
|
||||||
|
Self::ShiftRight => ">>",
|
||||||
|
Self::ShiftRightZeroFill => ">>>",
|
||||||
Self::BitwiseOR => "|",
|
Self::BitwiseOR => "|",
|
||||||
Self::BitwiseXOR => "^",
|
Self::BitwiseXOR => "^",
|
||||||
Self::BitwiseAnd => "&",
|
Self::BitwiseAnd => "&",
|
||||||
Self::In => "in",
|
Self::In => "in",
|
||||||
Self::Instanceof => "instanceof",
|
Self::Instanceof => "instanceof",
|
||||||
Self::Exponential => "**",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,12 +444,12 @@ impl GetPrecedence for LogicalOperator {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
#[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)]
|
#[generate_derive(CloneIn, ContentEq, ContentHash, ESTree)]
|
||||||
pub enum UnaryOperator {
|
pub enum UnaryOperator {
|
||||||
/// `-`
|
|
||||||
#[estree(rename = "-")]
|
|
||||||
UnaryNegation = 0,
|
|
||||||
/// `+`
|
/// `+`
|
||||||
#[estree(rename = "+")]
|
#[estree(rename = "+")]
|
||||||
UnaryPlus = 1,
|
UnaryPlus = 0,
|
||||||
|
/// `-`
|
||||||
|
#[estree(rename = "-")]
|
||||||
|
UnaryNegation = 1,
|
||||||
/// `!`
|
/// `!`
|
||||||
#[estree(rename = "!")]
|
#[estree(rename = "!")]
|
||||||
LogicalNot = 2,
|
LogicalNot = 2,
|
||||||
|
|
@ -470,24 +470,24 @@ pub enum UnaryOperator {
|
||||||
impl UnaryOperator {
|
impl UnaryOperator {
|
||||||
/// Returns `true` if this operator is a unary arithmetic operator.
|
/// Returns `true` if this operator is a unary arithmetic operator.
|
||||||
pub fn is_arithmetic(self) -> bool {
|
pub fn is_arithmetic(self) -> bool {
|
||||||
matches!(self, Self::UnaryNegation | Self::UnaryPlus)
|
matches!(self, Self::UnaryPlus | Self::UnaryNegation)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this operator is a [`LogicalNot`].
|
/// Returns `true` if this operator is a [`LogicalNot`].
|
||||||
///
|
///
|
||||||
/// [`LogicalNot`]: UnaryOperator::LogicalNot
|
/// [`LogicalNot`]: UnaryOperator::LogicalNot
|
||||||
pub fn is_not(self) -> bool {
|
pub fn is_not(self) -> bool {
|
||||||
matches!(self, Self::LogicalNot)
|
self == Self::LogicalNot
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this operator is a bitwise operator.
|
/// Returns `true` if this operator is a bitwise operator.
|
||||||
pub fn is_bitwise(self) -> bool {
|
pub fn is_bitwise(self) -> bool {
|
||||||
matches!(self, Self::BitwiseNot)
|
self == Self::BitwiseNot
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this is the [`void`](UnaryOperator::Void) operator.
|
/// Returns `true` if this is the [`void`](UnaryOperator::Void) operator.
|
||||||
pub fn is_void(self) -> bool {
|
pub fn is_void(self) -> bool {
|
||||||
matches!(self, Self::Void)
|
self == Self::Void
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this operator is a keyword instead of punctuation.
|
/// Returns `true` if this operator is a keyword instead of punctuation.
|
||||||
|
|
@ -498,8 +498,8 @@ impl UnaryOperator {
|
||||||
/// Get the string representation of this operator as it appears in source code.
|
/// Get the string representation of this operator as it appears in source code.
|
||||||
pub fn as_str(&self) -> &'static str {
|
pub fn as_str(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
Self::UnaryNegation => "-",
|
|
||||||
Self::UnaryPlus => "+",
|
Self::UnaryPlus => "+",
|
||||||
|
Self::UnaryNegation => "-",
|
||||||
Self::LogicalNot => "!",
|
Self::LogicalNot => "!",
|
||||||
Self::BitwiseNot => "~",
|
Self::BitwiseNot => "~",
|
||||||
Self::Typeof => "typeof",
|
Self::Typeof => "typeof",
|
||||||
|
|
|
||||||
18
npm/oxc-types/types.d.ts
vendored
18
npm/oxc-types/types.d.ts
vendored
|
|
@ -1714,16 +1714,16 @@ export type AssignmentOperator =
|
||||||
| '*='
|
| '*='
|
||||||
| '/='
|
| '/='
|
||||||
| '%='
|
| '%='
|
||||||
|
| '**='
|
||||||
| '<<='
|
| '<<='
|
||||||
| '>>='
|
| '>>='
|
||||||
| '>>>='
|
| '>>>='
|
||||||
| '|='
|
| '|='
|
||||||
| '^='
|
| '^='
|
||||||
| '&='
|
| '&='
|
||||||
| '&&='
|
|
||||||
| '||='
|
| '||='
|
||||||
| '??='
|
| '&&='
|
||||||
| '**=';
|
| '??=';
|
||||||
|
|
||||||
export type BinaryOperator =
|
export type BinaryOperator =
|
||||||
| '=='
|
| '=='
|
||||||
|
|
@ -1734,24 +1734,24 @@ export type BinaryOperator =
|
||||||
| '<='
|
| '<='
|
||||||
| '>'
|
| '>'
|
||||||
| '>='
|
| '>='
|
||||||
| '<<'
|
|
||||||
| '>>'
|
|
||||||
| '>>>'
|
|
||||||
| '+'
|
| '+'
|
||||||
| '-'
|
| '-'
|
||||||
| '*'
|
| '*'
|
||||||
| '/'
|
| '/'
|
||||||
| '%'
|
| '%'
|
||||||
|
| '**'
|
||||||
|
| '<<'
|
||||||
|
| '>>'
|
||||||
|
| '>>>'
|
||||||
| '|'
|
| '|'
|
||||||
| '^'
|
| '^'
|
||||||
| '&'
|
| '&'
|
||||||
| 'in'
|
| 'in'
|
||||||
| 'instanceof'
|
| 'instanceof';
|
||||||
| '**';
|
|
||||||
|
|
||||||
export type LogicalOperator = '||' | '&&' | '??';
|
export type LogicalOperator = '||' | '&&' | '??';
|
||||||
|
|
||||||
export type UnaryOperator = '-' | '+' | '!' | '~' | 'typeof' | 'void' | 'delete';
|
export type UnaryOperator = '+' | '-' | '!' | '~' | 'typeof' | 'void' | 'delete';
|
||||||
|
|
||||||
export type UpdateOperator = '++' | '--';
|
export type UpdateOperator = '++' | '--';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue