Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 23 additions & 42 deletions crates/oxc_parser/src/lexer/byte_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,28 +210,19 @@ ascii_byte_handler!(LIN(lexer) {
// !
ascii_byte_handler!(EXL(lexer) {
lexer.consume_char();
if let Some(next_2_bytes) = lexer.peek_2_bytes() {
match next_2_bytes[0] {
b'=' => {
if next_2_bytes[1] == b'=' {
lexer.consume_2_chars();
Kind::Neq2
} else {
lexer.consume_char();
Kind::Neq
}
}
_ => Kind::Bang
}
} else {
// At EOF, or only 1 byte left
match lexer.peek_byte() {
Some(b'=') => {
// Try to peek at next byte for common case first
match lexer.peek_byte() {
Some(b'=') => {
lexer.consume_char();
// Check for !== (triple equals)
if lexer.peek_byte() == Some(b'=') {
lexer.consume_char();
Kind::Neq2
} else {
Kind::Neq
}
_ => Kind::Bang
}
_ => Kind::Bang
}
});

Expand Down Expand Up @@ -428,37 +419,27 @@ ascii_byte_handler!(GTR(lexer) {
ascii_byte_handler!(QST(lexer) {
lexer.consume_char();

if let Some(next_2_bytes) = lexer.peek_2_bytes() {
match next_2_bytes[0] {
b'?' => {
if next_2_bytes[1] == b'=' {
lexer.consume_2_chars();
Kind::Question2Eq
} else {
lexer.consume_char();
Kind::Question2
}
}
// parse `?.1` as `?` `.1`
b'.' if !next_2_bytes[1].is_ascii_digit() => {
lexer.consume_char();
Kind::QuestionDot
}
_ => Kind::Question,
}
} else {
// At EOF, or only 1 byte left
match lexer.peek_byte() {
Some(b'?') => {
match lexer.peek_byte() {
Some(b'?') => {
lexer.consume_char();
// Check for ??= (nullish coalescing assignment)
if lexer.peek_byte() == Some(b'=') {
lexer.consume_char();
Kind::Question2Eq
} else {
Kind::Question2
}
Some(b'.') => {
}
Some(b'.') => {
// Only consume if not followed by digit (to parse `?.1` as `?` `.1`)
if lexer.peek_2_bytes().is_none_or(|bytes| !bytes[1].is_ascii_digit()) {
lexer.consume_char();
Kind::QuestionDot
} else {
Kind::Question
}
_ => Kind::Question,
}
_ => Kind::Question,
}
});

Expand Down
Loading