Skip to content

Commit

Permalink
refactor(parser): shorten lexer code (#4562)
Browse files Browse the repository at this point in the history
Use `lexer.peek_byte()` instead of `lexer.source.peek_byte()`.
  • Loading branch information
overlookmotel committed Jul 31, 2024
1 parent ab8509e commit 565eccf
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/lexer/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ impl<'a> Lexer<'a> {
/// Handle private identifier whose first byte is not an ASCII identifier start byte.
#[cold]
fn private_identifier_not_ascii_id(&mut self) -> Kind {
let b = self.source.peek_byte().unwrap();
let b = self.peek_byte().unwrap();
if !b.is_ascii() {
let c = self.peek_char().unwrap();
if is_identifier_start_unicode(c) {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/lexer/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'a> Lexer<'a> {
/// `JSXIdentifier` `IdentifierPart`
/// `JSXIdentifier` [no `WhiteSpace` or Comment here] -
pub(crate) fn continue_lex_jsx_identifier(&mut self) -> Option<Token> {
if self.source.peek_byte() != Some(b'-') {
if self.peek_byte() != Some(b'-') {
return None;
}
self.consume_char();
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<'a> Lexer<'a> {
let offset = self.offset();
self.token.start = offset;

let Some(byte) = self.source.peek_byte() else {
let Some(byte) = self.peek_byte() else {
return Kind::Eof;
};

Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_parser/src/lexer/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ macro_rules! handle_string_literal_escape {

// Consume bytes until reach end of string, line break, or another escape
let chunk_start = $lexer.source.position();
while let Some(b) = $lexer.source.peek_byte() {
while let Some(b) = $lexer.peek_byte() {
match b {
b if !$table.matches(b) => {
// SAFETY: A byte is available, as we just peeked it.
Expand Down

0 comments on commit 565eccf

Please sign in to comment.