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(oxc_allocator): Add new method clone_in_with_semantic_ids for CloneIn trait #8608

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
19 changes: 19 additions & 0 deletions crates/oxc_allocator/src/clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ pub trait CloneIn<'new_alloc>: Sized {
/// Clone `self` into the given `allocator`. `allocator` may be the same one
/// that `self` is already in.
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned;

/// Almost same as `clone_in`, but for some special type, it will also clone the semantic ids.
/// Please use this method only if you make sure the semantic info is synced with the ast.
#[inline]
fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
self.clone_in(allocator)
}
}

impl<'alloc, T, C> CloneIn<'alloc> for Option<T>
Expand All @@ -42,6 +49,10 @@ where
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
self.as_ref().map(|it| it.clone_in(allocator))
}

fn clone_in_with_semantic_ids(&self, allocator: &'alloc Allocator) -> Self::Cloned {
self.as_ref().map(|it| it.clone_in_with_semantic_ids(allocator))
}
}

impl<'new_alloc, T, C> CloneIn<'new_alloc> for Box<'_, T>
Expand All @@ -53,6 +64,10 @@ where
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Box::new_in(self.as_ref().clone_in(allocator), allocator)
}

fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Box::new_in(self.as_ref().clone_in_with_semantic_ids(allocator), allocator)
}
}

impl<'new_alloc, T, C> CloneIn<'new_alloc> for Vec<'_, T>
Expand All @@ -64,6 +79,10 @@ where
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Vec::from_iter_in(self.iter().map(|it| it.clone_in(allocator)), allocator)
}

fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Vec::from_iter_in(self.iter().map(|it| it.clone_in_with_semantic_ids(allocator)), allocator)
}
}

impl<'alloc, T: Copy> CloneIn<'alloc> for Cell<T> {
Expand Down
Loading
Loading