Skip to content

Commit

Permalink
Patch ES lexer
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jun 15, 2024
1 parent bdf8fe7 commit 8caf235
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions crates/swc_ecma_parser/src/lexer/jsx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,12 @@ impl<'a> Lexer<'a> {
let end = self.input.cur_pos();
let raw = unsafe {
// Safety: Both of `start` and `end` are generated from `cur_pos()`
self.input.slice(start, end)
self.input.slice_owned(start, end)
};

Ok(Token::Str {
value: self.atoms.atom(out),
raw: self.atoms.atom(raw),
raw,
})
}

Expand Down
12 changes: 6 additions & 6 deletions crates/swc_ecma_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,12 +993,12 @@ impl<'a> Lexer<'a> {
let raw = unsafe {
// Safety: start and end are valid position because we got them from
// `self.input`
l.input.slice(start, end)
l.input.slice_owned(start, end)
};

return Ok(Token::Str {
value: l.atoms.atom(&*out),
raw: l.atoms.atom(raw),
raw,
});
}
'\\' => {
Expand Down Expand Up @@ -1026,11 +1026,11 @@ impl<'a> Lexer<'a> {
let raw = unsafe {
// Safety: start and end are valid position because we got them from
// `self.input`
l.input.slice(start, end)
l.input.slice_owned(start, end)
};
Ok(Token::Str {
value: l.atoms.atom(&*out),
raw: l.atoms.atom(raw),
raw,
})
})
}
Expand Down Expand Up @@ -1164,11 +1164,11 @@ impl<'a> Lexer<'a> {
let raw = unsafe {
// Safety: Both of start and last_pos are valid position because we got them
// from `self.input`
self.input.slice(raw_slice_start, end)
self.input.slice_owned(raw_slice_start, end)
};
return Ok(Token::Template {
cooked: cooked.map(Atom::from),
raw: self.atoms.atom(raw),
raw,
});
}

Expand Down
10 changes: 7 additions & 3 deletions crates/swc_ecma_parser/src/lexer/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use either::Either;
use num_bigint::BigInt as BigIntValue;
use num_traits::{Num as NumTrait, ToPrimitive};
use smartstring::LazyCompact;
use swc_common::SyntaxContext;
use swc_common::{source_slice::SourceSlice, SyntaxContext};
use tracing::trace;

use super::*;
Expand All @@ -34,7 +34,7 @@ impl<'a> Lexer<'a> {
pub(super) fn read_number(
&mut self,
starts_with_dot: bool,
) -> LexResult<Either<(f64, Atom), (Box<BigIntValue>, Atom)>> {
) -> LexResult<Either<(f64, SourceSlice), (Box<BigIntValue>, SourceSlice)>> {
debug_assert!(self.cur().is_some());

if starts_with_dot {
Expand Down Expand Up @@ -68,6 +68,9 @@ impl<'a> Lexer<'a> {
Box::new(s.into_value()),
self.atoms.atom(raw),
)));
raw.extend(1);

return Ok(Either::Right((Box::new(s.into_value()), raw)));
}

write!(raw_val, "{}", &s.value).unwrap();
Expand Down Expand Up @@ -244,7 +247,7 @@ impl<'a> Lexer<'a> {
/// Returns `Left(value)` or `Right(BigInt)`
pub(super) fn read_radix_number<const RADIX: u8>(
&mut self,
) -> LexResult<Either<(f64, Atom), (Box<BigIntValue>, Atom)>> {
) -> LexResult<Either<(f64, SourceSlice), (Box<BigIntValue>, SourceSlice)>> {
debug_assert!(
RADIX == 2 || RADIX == 8 || RADIX == 16,
"radix should be one of 2, 8, 16, but got {}",
Expand Down Expand Up @@ -326,6 +329,7 @@ impl<'a> Lexer<'a> {
fn read_number_no_dot_as_str<const RADIX: u8>(
&mut self,
) -> LexResult<(f64, LazyBigInt<RADIX>, bool)> {
) -> LexResult<(f64, LazyBigInt<RADIX>, SourceSlice, bool)> {
debug_assert!(
RADIX == 2 || RADIX == 8 || RADIX == 10 || RADIX == 16,
"radix for read_number_no_dot should be one of 2, 8, 10, 16, but got {}",
Expand Down

0 comments on commit 8caf235

Please sign in to comment.