Skip to content

Commit

Permalink
refactor(parser): convert Lexer::read_minus to a single match (#4574)
Browse files Browse the repository at this point in the history
Same as #4573. Convert `Lexer::read_minus` to a single match rather than multiple `next_ascii_byte_eq` calls.
  • Loading branch information
overlookmotel committed Jul 31, 2024
1 parent ef5418a commit bba824b
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions crates/oxc_parser/src/lexer/punctuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,23 @@ impl<'a> Lexer<'a> {

/// returns None for `SingleLineHTMLCloseComment` `-->` in script mode
pub(super) fn read_minus(&mut self) -> Option<Kind> {
if self.next_ascii_byte_eq(b'-') {
// SingleLineHTMLCloseComment `-->` in script mode
if self.token.is_on_new_line
&& self.source_type.is_script()
&& self.next_ascii_byte_eq(b'>')
{
None
} else {
Some(Kind::Minus2)
match self.peek_byte() {
Some(b'-') => {
self.consume_char();
if self.token.is_on_new_line
&& self.source_type.is_script()
&& self.next_ascii_byte_eq(b'>')
{
None
} else {
Some(Kind::Minus2)
}
}
} else if self.next_ascii_byte_eq(b'=') {
Some(Kind::MinusEq)
} else {
Some(Kind::Minus)
Some(b'=') => {
self.consume_char();
Some(Kind::MinusEq)
}
_ => Some(Kind::Minus),
}
}

Expand Down

0 comments on commit bba824b

Please sign in to comment.