Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions crates/oxc_parser/src/lexer/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,26 @@ impl<'a> Lexer<'a> {
return self.escaped_strings[&token.start()];
}

let raw = &self.source.whole()[token.start() as usize..token.end() as usize];
match token.kind() {
let start = token.start() as usize;
let end = token.end() as usize;
let (start, end) = match token.kind() {
Kind::Str => {
&raw[1..raw.len() - 1] // omit surrounding quotes
// Omit surrounding quotes
(start + 1, end - 1)
}
Kind::PrivateIdentifier => {
&raw[1..] // omit leading `#`
// Omit leading `#`
(start + 1, end)
}
_ => raw,
}
_ => (start, end),
};
let whole_source = self.source.whole();
debug_assert!(start <= whole_source.len());
debug_assert!(end <= whole_source.len());
debug_assert!(start <= end);
debug_assert!(whole_source.is_char_boundary(start));
debug_assert!(whole_source.is_char_boundary(end));
// SAFETY: `token` is guaranteed to be within the source and on UTF-8 boundaries.
unsafe { whole_source.get_unchecked(start..end) }
}
}
Loading