refactor(parser): remove unsafe code in lexer (#2549)

Same as #2527. Just remove some unnecessary unsafe code, no substantive
changes.
This commit is contained in:
overlookmotel 2024-02-29 15:00:08 +00:00 committed by GitHub
parent 1391e4a86b
commit ddccaa1af9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -112,7 +112,7 @@ macro_rules! handle_string_literal_escape {
// `Source`'s invariant temporarily, but the guarantees of `SafeByteMatchTable` // `Source`'s invariant temporarily, but the guarantees of `SafeByteMatchTable`
// mean `!table.matches(b)` on this branch prevents exiting this loop until // mean `!table.matches(b)` on this branch prevents exiting this loop until
// `source` is positioned on a UTF-8 character boundary again. // `source` is positioned on a UTF-8 character boundary again.
unsafe { $lexer.source.next_byte_unchecked() }; $lexer.source.next_byte_unchecked();
continue; continue;
} }
b if b == $delimiter => { b if b == $delimiter => {
@ -132,16 +132,15 @@ macro_rules! handle_string_literal_escape {
str.push_str(chunk); str.push_str(chunk);
continue 'outer; continue 'outer;
} }
b'\r' | b'\n' => { _ => {
// This is impossible in valid JS, so cold path // Line break. This is impossible in valid JS, so cold path.
return cold_branch(|| { return cold_branch(|| {
debug_assert!(matches!(b, b'\r' | b'\n'));
$lexer.consume_char(); $lexer.consume_char();
$lexer.error(diagnostics::UnterminatedString($lexer.unterminated_range())); $lexer.error(diagnostics::UnterminatedString($lexer.unterminated_range()));
Kind::Undetermined Kind::Undetermined
}); });
} }
// SAFETY: Caller guarantees `table` does not match any other bytes
_ => assert_unchecked::unreachable_unchecked!(),
} }
} }