refactor(parser): shorten lexer code (#4562)

Use `lexer.peek_byte()` instead of `lexer.source.peek_byte()`.
This commit is contained in:
overlookmotel 2024-07-31 00:28:48 +00:00
parent ab8509edaa
commit 565eccf631
4 changed files with 4 additions and 4 deletions

View file

@ -270,7 +270,7 @@ impl<'a> Lexer<'a> {
/// Handle private identifier whose first byte is not an ASCII identifier start byte. /// Handle private identifier whose first byte is not an ASCII identifier start byte.
#[cold] #[cold]
fn private_identifier_not_ascii_id(&mut self) -> Kind { 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() { if !b.is_ascii() {
let c = self.peek_char().unwrap(); let c = self.peek_char().unwrap();
if is_identifier_start_unicode(c) { if is_identifier_start_unicode(c) {

View file

@ -99,7 +99,7 @@ impl<'a> Lexer<'a> {
/// `JSXIdentifier` `IdentifierPart` /// `JSXIdentifier` `IdentifierPart`
/// `JSXIdentifier` [no `WhiteSpace` or Comment here] - /// `JSXIdentifier` [no `WhiteSpace` or Comment here] -
pub(crate) fn continue_lex_jsx_identifier(&mut self) -> Option<Token> { 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; return None;
} }
self.consume_char(); self.consume_char();

View file

@ -309,7 +309,7 @@ impl<'a> Lexer<'a> {
let offset = self.offset(); let offset = self.offset();
self.token.start = offset; self.token.start = offset;
let Some(byte) = self.source.peek_byte() else { let Some(byte) = self.peek_byte() else {
return Kind::Eof; return Kind::Eof;
}; };

View file

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