diff --git a/crates/oxc_parser/src/cursor.rs b/crates/oxc_parser/src/cursor.rs index 59fcf3fea..a33c70816 100644 --- a/crates/oxc_parser/src/cursor.rs +++ b/crates/oxc_parser/src/cursor.rs @@ -70,7 +70,7 @@ impl<'a> Parser<'a> { } /// Peek nth token - pub fn nth(&mut self, n: usize) -> &Token { + pub fn nth(&mut self, n: u8) -> &Token { if n == 0 { return self.cur_token(); } @@ -78,12 +78,12 @@ impl<'a> Parser<'a> { } /// Peek at nth kind - pub fn nth_at(&mut self, n: usize, kind: Kind) -> bool { + pub fn nth_at(&mut self, n: u8, kind: Kind) -> bool { self.nth(n).kind == kind } /// Peek nth kind - pub fn nth_kind(&mut self, n: usize) -> Kind { + pub fn nth_kind(&mut self, n: u8) -> Kind { self.nth(n).kind } diff --git a/crates/oxc_parser/src/js/function.rs b/crates/oxc_parser/src/js/function.rs index 90ebfedf1..9e6da6d55 100644 --- a/crates/oxc_parser/src/js/function.rs +++ b/crates/oxc_parser/src/js/function.rs @@ -328,7 +328,7 @@ impl<'a> Parser<'a> { &mut self, r#async: bool, ) -> IsParenthesizedArrowFunction { - let offset = usize::from(r#async); + let offset = u8::from(r#async); match self.nth_kind(offset) { Kind::LParen => match self.nth_kind(offset + 1) { diff --git a/crates/oxc_parser/src/lexer/mod.rs b/crates/oxc_parser/src/lexer/mod.rs index 23e8c28d4..302850b41 100644 --- a/crates/oxc_parser/src/lexer/mod.rs +++ b/crates/oxc_parser/src/lexer/mod.rs @@ -114,7 +114,8 @@ impl<'a> Lexer<'a> { } /// Find the nth lookahead token lazily - pub fn lookahead(&mut self, n: usize) -> &Token { + pub fn lookahead(&mut self, n: u8) -> &Token { + let n = n as usize; debug_assert!(n > 0); if self.lookahead.len() > n - 1 { diff --git a/crates/oxc_parser/src/ts/statement.rs b/crates/oxc_parser/src/ts/statement.rs index cb5097799..23d7a6601 100644 --- a/crates/oxc_parser/src/ts/statement.rs +++ b/crates/oxc_parser/src/ts/statement.rs @@ -183,7 +183,7 @@ impl<'a> Parser<'a> { self.nth_at(offset + 2, Kind::Colon) } - pub fn is_nth_at_modifier(&mut self, n: usize, is_constructor_parameter: bool) -> bool { + pub fn is_nth_at_modifier(&mut self, n: u8, is_constructor_parameter: bool) -> bool { let nth = self.nth(n); if !(matches!( nth.kind, @@ -299,7 +299,7 @@ impl<'a> Parser<'a> { .map(|decl| Statement::Declaration(Declaration::TSModuleDeclaration(decl))) } - pub fn is_nth_at_ts_namespace_declaration(&mut self, n: usize) -> bool { + pub fn is_nth_at_ts_namespace_declaration(&mut self, n: u8) -> bool { if self.nth(n + 1).is_on_new_line { return false; } diff --git a/crates/oxc_parser/src/ts/types.rs b/crates/oxc_parser/src/ts/types.rs index fe73b80b9..509b0b379 100644 --- a/crates/oxc_parser/src/ts/types.rs +++ b/crates/oxc_parser/src/ts/types.rs @@ -616,7 +616,7 @@ impl<'a> Parser<'a> { } pub fn is_at_named_tuple_element(&mut self) -> bool { - let offset = usize::from(self.at(Kind::Dot3)); + let offset = u8::from(self.at(Kind::Dot3)); let has_colon = self.nth_at(offset + 1, Kind::Colon); let has_question_colon = self.nth_at(offset + 1, Kind::Question) && self.nth_at(offset + 2, Kind::Colon);