From d0d708295b57a0c4f4aa277cafda47f22842a178 Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Thu, 1 Feb 2024 03:34:26 +0000 Subject: [PATCH] refactor(parser): consume chars when parsing surrogate pair escape (#2243) This fixes a mistake I made in #2237. I was confused by the `!(...)` wrapping of the preceding `if` test and missed that there are definitely 2 chars to consume, so can use `consume_char()` instead of `next_char()`. This makes no difference to behavior, but it follows the convention to always prefer `consume_char()` when possible. I've also refactored the code which confused me, so hopefully others won't be confused too! --- crates/oxc_parser/src/lexer/unicode.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/oxc_parser/src/lexer/unicode.rs b/crates/oxc_parser/src/lexer/unicode.rs index 0a122b674..1960cdee4 100644 --- a/crates/oxc_parser/src/lexer/unicode.rs +++ b/crates/oxc_parser/src/lexer/unicode.rs @@ -189,15 +189,15 @@ impl<'a> Lexer<'a> { fn surrogate_pair(&mut self) -> Option { let high = self.hex_4_digits()?; // The first code unit of a surrogate pair is always in the range from 0xD800 to 0xDBFF, and is called a high surrogate or a lead surrogate. - if !((0xD800..=0xDBFF).contains(&high) + let is_pair = (0xD800..=0xDBFF).contains(&high) && self.peek() == Some('\\') - && self.peek2() == Some('u')) - { + && self.peek2() == Some('u'); + if !is_pair { return Some(SurrogatePair::CodePoint(high)); } - self.next_char(); - self.next_char(); + self.consume_char(); + self.consume_char(); let low = self.hex_4_digits()?;