diff --git a/crates/oxc_parser/src/lexer/string.rs b/crates/oxc_parser/src/lexer/string.rs index 74a8b7aed16bb..4f02169dcafdf 100644 --- a/crates/oxc_parser/src/lexer/string.rs +++ b/crates/oxc_parser/src/lexer/string.rs @@ -270,6 +270,12 @@ impl<'a> Lexer<'a> { } _ => {} } - &source_text[start..end] + debug_assert!(start <= source_text.len()); + debug_assert!(end <= source_text.len()); + debug_assert!(start <= end); + debug_assert!(source_text.is_char_boundary(start)); + debug_assert!(source_text.is_char_boundary(end)); + // SAFETY: `token` is guaranteed to be within the source and on UTF-8 boundaries. + unsafe { source_text.get_unchecked(start..end) } } }