mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
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!
This commit is contained in:
parent
9bbdec146f
commit
d0d708295b
1 changed files with 5 additions and 5 deletions
|
|
@ -189,15 +189,15 @@ impl<'a> Lexer<'a> {
|
||||||
fn surrogate_pair(&mut self) -> Option<SurrogatePair> {
|
fn surrogate_pair(&mut self) -> Option<SurrogatePair> {
|
||||||
let high = self.hex_4_digits()?;
|
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.
|
// 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.peek() == Some('\\')
|
||||||
&& self.peek2() == Some('u'))
|
&& self.peek2() == Some('u');
|
||||||
{
|
if !is_pair {
|
||||||
return Some(SurrogatePair::CodePoint(high));
|
return Some(SurrogatePair::CodePoint(high));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.next_char();
|
self.consume_char();
|
||||||
self.next_char();
|
self.consume_char();
|
||||||
|
|
||||||
let low = self.hex_4_digits()?;
|
let low = self.hex_4_digits()?;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue