Skip to content

Commit 977d3ba

Browse files
committed
style(lexer): reformat Kind matchers (#12520)
Pure style refactor: * Use `==` instead of `matches!` when matching a single variant. * Reformat multi-line `matches!` blocks. (found this old branch lying around from March which I'd never got around to submitting)
1 parent 23f7f82 commit 977d3ba

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

crates/oxc_parser/src/lexer/kind.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ use Kind::*;
203203
impl Kind {
204204
#[inline]
205205
pub fn is_eof(self) -> bool {
206-
matches!(self, Eof)
206+
self == Eof
207207
}
208208

209209
#[inline]
@@ -268,7 +268,7 @@ impl Kind {
268268
/// `IdentifierName`
269269
#[inline]
270270
pub fn is_identifier_name(self) -> bool {
271-
matches!(self, Ident) || self.is_any_keyword()
271+
self == Ident || self.is_any_keyword()
272272
}
273273

274274
/// Check the succeeding token of a `let` keyword.
@@ -310,7 +310,7 @@ impl Kind {
310310

311311
#[inline]
312312
pub fn is_identifier_or_keyword(self) -> bool {
313-
self.is_literal_property_name() || matches!(self, Self::PrivateIdentifier)
313+
self.is_literal_property_name() || self == Self::PrivateIdentifier
314314
}
315315

316316
#[inline]
@@ -321,17 +321,21 @@ impl Kind {
321321
#[rustfmt::skip]
322322
#[inline]
323323
pub fn is_assignment_operator(self) -> bool {
324-
matches!(self, Eq | PlusEq | MinusEq | StarEq | SlashEq | PercentEq | ShiftLeftEq | ShiftRightEq
325-
| ShiftRight3Eq | Pipe2Eq | Amp2Eq | PipeEq | CaretEq | AmpEq | Question2Eq
326-
| Star2Eq)
324+
matches!(
325+
self,
326+
Eq | PlusEq | MinusEq | StarEq | SlashEq | PercentEq | ShiftLeftEq | ShiftRightEq
327+
| ShiftRight3Eq | Pipe2Eq | Amp2Eq | PipeEq | CaretEq | AmpEq | Question2Eq | Star2Eq
328+
)
327329
}
328330

329331
#[rustfmt::skip]
330332
#[inline]
331333
pub fn is_binary_operator(self) -> bool {
332-
matches!(self, Eq2 | Neq | Eq3 | Neq2 | LAngle | LtEq | RAngle | GtEq | ShiftLeft | ShiftRight
333-
| ShiftRight3 | Plus | Minus | Star | Slash | Percent | Pipe | Caret | Amp | In
334-
| Instanceof | Star2)
334+
matches!(
335+
self,
336+
Eq2 | Neq | Eq3 | Neq2 | LAngle | LtEq | RAngle | GtEq | ShiftLeft | ShiftRight | ShiftRight3
337+
| Plus | Minus | Star | Slash | Percent | Pipe | Caret | Amp | In | Instanceof | Star2
338+
)
335339
}
336340

337341
#[inline]
@@ -361,10 +365,13 @@ impl Kind {
361365
#[rustfmt::skip]
362366
#[inline]
363367
pub fn is_reserved_keyword(self) -> bool {
364-
matches!(self, Await | Break | Case | Catch | Class | Const | Continue | Debugger | Default
368+
matches!(
369+
self,
370+
Await | Break | Case | Catch | Class | Const | Continue | Debugger | Default
365371
| Delete | Do | Else | Enum | Export | Extends | False | Finally | For | Function | If
366372
| Import | In | Instanceof | New | Null | Return | Super | Switch | This | Throw
367-
| True | Try | Typeof | Var | Void | While | With | Yield)
373+
| True | Try | Typeof | Var | Void | While | With | Yield
374+
)
368375
}
369376

370377
#[rustfmt::skip]
@@ -376,12 +383,13 @@ impl Kind {
376383
#[rustfmt::skip]
377384
#[inline]
378385
pub fn is_contextual_keyword(self) -> bool {
379-
matches!(self, Async | From | Get | Meta | Of | Set | Target | Accessor | Abstract | As | Asserts
380-
| Assert | Any | Boolean | Constructor | Declare | Infer | Intrinsic | Is | KeyOf | Module
381-
| Namespace | Never | Out | Readonly | Require | Number | Object | Satisfies | String
382-
| Symbol | Type | Undefined | Unique | Unknown | Using | Global | BigInt | Override
383-
| Source | Defer
384-
)
386+
matches!(
387+
self,
388+
Async | From | Get | Meta | Of | Set | Target | Accessor | Abstract | As | Asserts | Assert
389+
| Any | Boolean | Constructor | Declare | Infer | Intrinsic | Is | KeyOf | Module | Namespace
390+
| Never | Out | Readonly | Require | Number | Object | Satisfies | String | Symbol | Type
391+
| Undefined | Unique | Unknown | Using | Global | BigInt | Override | Source | Defer
392+
)
385393
}
386394

387395
#[rustfmt::skip]
@@ -398,8 +406,11 @@ impl Kind {
398406
#[rustfmt::skip]
399407
#[inline]
400408
pub fn is_modifier_kind(self) -> bool {
401-
matches!(self, Abstract | Accessor | Async | Const | Declare
402-
| In | Out | Public | Private | Protected | Readonly | Static | Override)
409+
matches!(
410+
self,
411+
Abstract | Accessor | Async | Const | Declare
412+
| In | Out | Public | Private | Protected | Readonly | Static | Override
413+
)
403414
}
404415

405416
#[inline]

0 commit comments

Comments
 (0)