mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
perf(parser): eat whitespace after line break (#2353)
Uses the `byte_search!` macro introduced in #2352 to consume whitespace after a line break.
This commit is contained in:
parent
d3a59f27f7
commit
8376f15b9a
3 changed files with 30 additions and 2 deletions
|
|
@ -203,8 +203,7 @@ ascii_byte_handler!(ISP(lexer) {
|
|||
// '\r' '\n'
|
||||
ascii_byte_handler!(LIN(lexer) {
|
||||
lexer.consume_char();
|
||||
lexer.token.is_on_new_line = true;
|
||||
Kind::Skip
|
||||
lexer.line_break_handler()
|
||||
});
|
||||
|
||||
// !
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ mod token;
|
|||
mod trivia_builder;
|
||||
mod typescript;
|
||||
mod unicode;
|
||||
mod whitespace;
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::collections::VecDeque;
|
||||
|
|
|
|||
28
crates/oxc_parser/src/lexer/whitespace.rs
Normal file
28
crates/oxc_parser/src/lexer/whitespace.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
use super::{
|
||||
search::{byte_search, safe_byte_match_table, SafeByteMatchTable},
|
||||
Kind, Lexer,
|
||||
};
|
||||
|
||||
static NOT_REGULAR_WHITESPACE_OR_LINE_BREAK_TABLE: SafeByteMatchTable =
|
||||
safe_byte_match_table!(|b| !matches!(b, b' ' | b'\t' | b'\r' | b'\n'));
|
||||
|
||||
impl<'a> Lexer<'a> {
|
||||
pub(super) fn line_break_handler(&mut self) -> Kind {
|
||||
self.token.is_on_new_line = true;
|
||||
|
||||
// Indentation is common after a line break.
|
||||
// Consume it, along with any further line breaks.
|
||||
// Irregular line breaks and whitespace are not consumed.
|
||||
// They're uncommon, so leave them for the next call to `handle_byte` to take care of.
|
||||
byte_search! {
|
||||
lexer: self,
|
||||
table: NOT_REGULAR_WHITESPACE_OR_LINE_BREAK_TABLE,
|
||||
handle_match: |_next_byte, _start| {
|
||||
Kind::Skip
|
||||
},
|
||||
handle_eof: |_start| {
|
||||
Kind::Skip
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue