Skip to content

Commit

Permalink
refactor(syntax): add explicit enum discriminants to AST related type…
Browse files Browse the repository at this point in the history
…s. (#4691)
  • Loading branch information
rzvxa committed Aug 6, 2024
1 parent 83b6ca9 commit e24fb5b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 59 deletions.
20 changes: 11 additions & 9 deletions crates/oxc_syntax/src/number.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum NumberBase {
Float,
Decimal,
Binary,
Octal,
Hex,
Float = 0,
Decimal = 1,
Binary = 2,
Octal = 3,
Hex = 4,
}

impl NumberBase {
Expand All @@ -13,12 +14,13 @@ impl NumberBase {
}
}

#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BigintBase {
Decimal,
Binary,
Octal,
Hex,
Decimal = 0,
Binary = 1,
Octal = 2,
Hex = 3,
}

impl BigintBase {
Expand Down
105 changes: 55 additions & 50 deletions crates/oxc_syntax/src/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,42 @@ use tsify::Tsify;

use crate::precedence::{GetPrecedence, Precedence};

#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
pub enum AssignmentOperator {
#[cfg_attr(feature = "serialize", serde(rename = "="))]
Assign,
Assign = 0,
#[cfg_attr(feature = "serialize", serde(rename = "+="))]
Addition,
Addition = 1,
#[cfg_attr(feature = "serialize", serde(rename = "-="))]
Subtraction,
Subtraction = 2,
#[cfg_attr(feature = "serialize", serde(rename = "*="))]
Multiplication,
Multiplication = 3,
#[cfg_attr(feature = "serialize", serde(rename = "/="))]
Division,
Division = 4,
#[cfg_attr(feature = "serialize", serde(rename = "%="))]
Remainder,
Remainder = 5,
#[cfg_attr(feature = "serialize", serde(rename = "<<="))]
ShiftLeft,
ShiftLeft = 6,
#[cfg_attr(feature = "serialize", serde(rename = ">>="))]
ShiftRight,
ShiftRight = 7,
#[cfg_attr(feature = "serialize", serde(rename = ">>>="))]
ShiftRightZeroFill,
ShiftRightZeroFill = 8,
#[cfg_attr(feature = "serialize", serde(rename = "|="))]
BitwiseOR,
BitwiseOR = 9,
#[cfg_attr(feature = "serialize", serde(rename = "^="))]
BitwiseXOR,
BitwiseXOR = 10,
#[cfg_attr(feature = "serialize", serde(rename = "&="))]
BitwiseAnd,
BitwiseAnd = 11,
#[cfg_attr(feature = "serialize", serde(rename = "&&="))]
LogicalAnd,
LogicalAnd = 12,
#[cfg_attr(feature = "serialize", serde(rename = "||="))]
LogicalOr,
LogicalOr = 13,
#[cfg_attr(feature = "serialize", serde(rename = "??="))]
LogicalNullish,
LogicalNullish = 14,
#[cfg_attr(feature = "serialize", serde(rename = "**="))]
Exponential,
Exponential = 15,
}

impl AssignmentOperator {
Expand Down Expand Up @@ -86,53 +87,54 @@ impl AssignmentOperator {
}
}

#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
pub enum BinaryOperator {
#[cfg_attr(feature = "serialize", serde(rename = "=="))]
Equality,
Equality = 0,
#[cfg_attr(feature = "serialize", serde(rename = "!="))]
Inequality,
Inequality = 1,
#[cfg_attr(feature = "serialize", serde(rename = "==="))]
StrictEquality,
StrictEquality = 2,
#[cfg_attr(feature = "serialize", serde(rename = "!=="))]
StrictInequality,
StrictInequality = 3,
#[cfg_attr(feature = "serialize", serde(rename = "<"))]
LessThan,
LessThan = 4,
#[cfg_attr(feature = "serialize", serde(rename = "<="))]
LessEqualThan,
LessEqualThan = 5,
#[cfg_attr(feature = "serialize", serde(rename = ">"))]
GreaterThan,
GreaterThan = 6,
#[cfg_attr(feature = "serialize", serde(rename = ">="))]
GreaterEqualThan,
GreaterEqualThan = 7,
#[cfg_attr(feature = "serialize", serde(rename = "<<"))]
ShiftLeft,
ShiftLeft = 8,
#[cfg_attr(feature = "serialize", serde(rename = ">>"))]
ShiftRight,
ShiftRight = 9,
#[cfg_attr(feature = "serialize", serde(rename = ">>>"))]
ShiftRightZeroFill,
ShiftRightZeroFill = 10,
#[cfg_attr(feature = "serialize", serde(rename = "+"))]
Addition,
Addition = 11,
#[cfg_attr(feature = "serialize", serde(rename = "-"))]
Subtraction,
Subtraction = 12,
#[cfg_attr(feature = "serialize", serde(rename = "*"))]
Multiplication,
Multiplication = 13,
#[cfg_attr(feature = "serialize", serde(rename = "/"))]
Division,
Division = 14,
#[cfg_attr(feature = "serialize", serde(rename = "%"))]
Remainder,
Remainder = 15,
#[cfg_attr(feature = "serialize", serde(rename = "|"))]
BitwiseOR,
BitwiseOR = 16,
#[cfg_attr(feature = "serialize", serde(rename = "^"))]
BitwiseXOR,
BitwiseXOR = 17,
#[cfg_attr(feature = "serialize", serde(rename = "&"))]
BitwiseAnd,
BitwiseAnd = 18,
#[cfg_attr(feature = "serialize", serde(rename = "in"))]
In,
In = 19,
#[cfg_attr(feature = "serialize", serde(rename = "instanceof"))]
Instanceof,
Instanceof = 20,
#[cfg_attr(feature = "serialize", serde(rename = "**"))]
Exponential,
Exponential = 21,
}

impl BinaryOperator {
Expand Down Expand Up @@ -273,16 +275,17 @@ impl GetPrecedence for BinaryOperator {
}
}

#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "serialize", derive(Tsify))]
pub enum LogicalOperator {
#[cfg_attr(feature = "serialize", serde(rename = "||"))]
Or,
Or = 0,
#[cfg_attr(feature = "serialize", serde(rename = "&&"))]
And,
And = 1,
#[cfg_attr(feature = "serialize", serde(rename = "??"))]
Coalesce,
Coalesce = 2,
}

impl LogicalOperator {
Expand Down Expand Up @@ -313,24 +316,25 @@ impl GetPrecedence for LogicalOperator {
}
}

#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "serialize", derive(Tsify))]
pub enum UnaryOperator {
#[cfg_attr(feature = "serialize", serde(rename = "-"))]
UnaryNegation,
UnaryNegation = 0,
#[cfg_attr(feature = "serialize", serde(rename = "+"))]
UnaryPlus,
UnaryPlus = 1,
#[cfg_attr(feature = "serialize", serde(rename = "!"))]
LogicalNot,
LogicalNot = 2,
#[cfg_attr(feature = "serialize", serde(rename = "~"))]
BitwiseNot,
BitwiseNot = 3,
#[cfg_attr(feature = "serialize", serde(rename = "typeof"))]
Typeof,
Typeof = 4,
#[cfg_attr(feature = "serialize", serde(rename = "void"))]
Void,
Void = 5,
#[cfg_attr(feature = "serialize", serde(rename = "delete"))]
Delete,
Delete = 6,
}

impl UnaryOperator {
Expand Down Expand Up @@ -366,14 +370,15 @@ impl UnaryOperator {
}
}

#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "serialize", derive(Tsify))]
pub enum UpdateOperator {
#[cfg_attr(feature = "serialize", serde(rename = "++"))]
Increment,
Increment = 0,
#[cfg_attr(feature = "serialize", serde(rename = "--"))]
Decrement,
Decrement = 1,
}

impl UpdateOperator {
Expand Down

0 comments on commit e24fb5b

Please sign in to comment.