Skip to content
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
33 changes: 10 additions & 23 deletions crates/oxc_parser/src/lexer/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ pub enum Kind {
Public,
Static,
Yield,
// 12.9.1 Null Literals
// 12.9.2 Boolean Literals
// Moved here to make all keywords contiguous for range check optimization
True,
False,
Null,
// 12.8 punctuators
Amp, // &
Amp2,
Expand Down Expand Up @@ -164,11 +170,6 @@ pub enum Kind {
Tilde,
// arrow function
Arrow,
// 12.9.1 Null Literals
Null,
// 12.9.2 Boolean Literals
True,
False,
// 12.9.3 Numeric Literals
Decimal,
Float,
Expand Down Expand Up @@ -211,22 +212,10 @@ impl Kind {
self == Eof
}

/// All numeric literals are contiguous from Decimal..=HexBigInt in the enum.
#[inline]
pub fn is_number(self) -> bool {
matches!(
self,
Float
| Decimal
| Binary
| Octal
| Hex
| PositiveExponential
| NegativeExponential
| DecimalBigInt
| BinaryBigInt
| OctalBigInt
| HexBigInt
)
matches!(self as u8, x if x >= Decimal as u8 && x <= HexBigInt as u8)
}

#[inline] // Inline into `read_non_decimal` - see comment there as to why
Expand Down Expand Up @@ -364,12 +353,10 @@ impl Kind {
}

/// [Keywords and Reserved Words](https://tc39.es/ecma262/#sec-keywords-and-reserved-words)
/// All keywords are contiguous from Await..=Null in the enum for optimal range check.
#[inline]
pub fn is_any_keyword(self) -> bool {
self.is_reserved_keyword()
|| self.is_contextual_keyword()
|| self.is_strict_mode_contextual_keyword()
|| self.is_future_reserved_keyword()
matches!(self as u8, x if x >= Await as u8 && x <= Null as u8)
}

#[rustfmt::skip]
Expand Down
Loading