Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(span): add impl From<ArenaString> for Atom #7973

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast_builder_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'a> AstBuilder<'a> {
/// Allocate an [`Atom`] from a string slice.
#[inline]
pub fn atom(self, value: &str) -> Atom<'a> {
Atom::from(String::from_str_in(value, self.allocator).into_bump_str())
Atom::from_in(value, self.allocator)
}

/// # SAFETY
Expand Down
8 changes: 7 additions & 1 deletion crates/oxc_span/src/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<'alloc> FromIn<'alloc, &Atom<'alloc>> for Atom<'alloc> {

impl<'alloc> FromIn<'alloc, &str> for Atom<'alloc> {
fn from_in(s: &str, allocator: &'alloc Allocator) -> Self {
Self::from(oxc_allocator::String::from_str_in(s, allocator).into_bump_str())
Self::from(oxc_allocator::String::from_str_in(s, allocator))
}
}

Expand Down Expand Up @@ -101,6 +101,12 @@ impl<'a> From<&'a str> for Atom<'a> {
}
}

impl<'alloc> From<oxc_allocator::String<'alloc>> for Atom<'alloc> {
fn from(s: oxc_allocator::String<'alloc>) -> Self {
Self::from(s.into_bump_str())
}
}

impl<'a> From<Atom<'a>> for &'a str {
fn from(s: Atom<'a>) -> Self {
s.as_str()
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/common/helper_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl<'a> HelperLoaderStore<'a> {
source.push_str(&self.module_name);
source.push_str("/helpers/");
source.push_str(helper_name);
Atom::from(source.into_bump_str())
Atom::from(source)
}

fn transform_for_external_helper(helper: Helper, ctx: &mut TraverseCtx<'a>) -> Expression<'a> {
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/es2022/class_static_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl<'a> Keys<'a> {
let mut key = ArenaString::with_capacity_in(num_str.len() + 1, ctx.ast.allocator);
key.push('_');
key.push_str(num_str);
let key = Atom::from(key.into_bump_str());
let key = Atom::from(key);

self.numbered.push(&key.as_str()[1..]);

Expand Down
Loading