From 0ddfc856d2ef8e67f7f7b832175ad3beade3819e Mon Sep 17 00:00:00 2001 From: overlookmotel Date: Tue, 27 Feb 2024 12:28:21 +0000 Subject: [PATCH] refactor(parser): remove unsafe code (#2527) Remove some unnecessary unsafe code. --- crates/oxc_parser/src/lexer/string.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/oxc_parser/src/lexer/string.rs b/crates/oxc_parser/src/lexer/string.rs index 009295792..8325d2f95 100644 --- a/crates/oxc_parser/src/lexer/string.rs +++ b/crates/oxc_parser/src/lexer/string.rs @@ -51,16 +51,15 @@ macro_rules! handle_string_literal { handle_string_literal_escape!($lexer, $delimiter, $table, after_opening_quote) }) }, - b'\r' | b'\n' => { - // This is impossible in valid JS, so cold path + _ => { + // Line break. This is impossible in valid JS, so cold path. cold_branch(|| { + debug_assert!(matches!(next_byte, b'\r' | b'\n')); $lexer.consume_char(); $lexer.error(diagnostics::UnterminatedString($lexer.unterminated_range())); Kind::Undetermined }) - }, - // SAFETY: Macro user guarantees `$table` does not match any other bytes - _ => assert_unchecked::unreachable_unchecked!() + } } }, handle_eof: || {