mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(span): implement CloneIn for the AST-related items. (#4729)
Follow-on after #4276, related to #4284.
This commit is contained in:
parent
23b0040c16
commit
2e63618462
3 changed files with 27 additions and 1 deletions
|
|
@ -9,7 +9,7 @@ use compact_str::CompactString;
|
||||||
use serde::{Serialize, Serializer};
|
use serde::{Serialize, Serializer};
|
||||||
|
|
||||||
use crate::Span;
|
use crate::Span;
|
||||||
use oxc_allocator::{Allocator, FromIn};
|
use oxc_allocator::{Allocator, CloneIn, FromIn};
|
||||||
|
|
||||||
#[cfg(feature = "serialize")]
|
#[cfg(feature = "serialize")]
|
||||||
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
|
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
|
||||||
|
|
@ -59,6 +59,14 @@ impl<'a> Atom<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for Atom<'old_alloc> {
|
||||||
|
type Cloned = Atom<'new_alloc>;
|
||||||
|
|
||||||
|
fn clone_in(&self, alloc: &'new_alloc Allocator) -> Self::Cloned {
|
||||||
|
Atom::from_in(self.as_str(), alloc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, 'b> FromIn<'a, &'b Atom<'a>> for Atom<'a> {
|
impl<'a, 'b> FromIn<'a, &'b Atom<'a>> for Atom<'a> {
|
||||||
fn from_in(s: &'b Atom<'a>, _: &'a Allocator) -> Self {
|
fn from_in(s: &'b Atom<'a>, _: &'a Allocator) -> Self {
|
||||||
Self::from(s.0)
|
Self::from(s.0)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
mod types;
|
mod types;
|
||||||
|
use oxc_allocator::{Allocator, CloneIn};
|
||||||
pub use types::*;
|
pub use types::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -17,6 +18,14 @@ impl Default for SourceType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> CloneIn<'a> for SourceType {
|
||||||
|
type Cloned = Self;
|
||||||
|
#[inline]
|
||||||
|
fn clone_in(&self, _: &'a Allocator) -> Self {
|
||||||
|
*self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Valid file extensions
|
/// Valid file extensions
|
||||||
pub const VALID_EXTENSIONS: [&str; 8] = ["js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx"];
|
pub const VALID_EXTENSIONS: [&str; 8] = ["js", "mjs", "cjs", "jsx", "ts", "mts", "cts", "tsx"];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use std::{
|
||||||
use miette::{LabeledSpan, SourceOffset, SourceSpan};
|
use miette::{LabeledSpan, SourceOffset, SourceSpan};
|
||||||
|
|
||||||
mod types;
|
mod types;
|
||||||
|
use oxc_allocator::{Allocator, CloneIn};
|
||||||
pub use types::Span;
|
pub use types::Span;
|
||||||
|
|
||||||
/// An Empty span useful for creating AST nodes.
|
/// An Empty span useful for creating AST nodes.
|
||||||
|
|
@ -338,6 +339,14 @@ impl GetSpanMut for Span {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> CloneIn<'a> for Span {
|
||||||
|
type Cloned = Self;
|
||||||
|
#[inline]
|
||||||
|
fn clone_in(&self, _: &'a Allocator) -> Self {
|
||||||
|
*self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::Span;
|
use super::Span;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue