Skip to main content

OwnedSourceMap

Struct OwnedSourceMap 

Source
pub struct OwnedSourceMap { /* private fields */ }
Expand description

An owned, lifetime-free source map.

OwnedSourceMap is a thin wrapper around SourceMap<'static>. It exists so that downstream code that stores sourcemaps as long-lived struct fields can write Option<OwnedSourceMap> instead of Option<SourceMap<'static>>, keeping the 'static lifetime annotation out of the public type names.

Internally this is just SourceMap<'static> — same allocation model, same methods. For the zero-copy-parse case, prefer the lifetime-parameterized SourceMap<'a> directly.

use oxc_sourcemap::{OwnedSourceMap, SourceMap, SourceMapBuilder};

// From a builder (always owned):
let owned: OwnedSourceMap = SourceMapBuilder::default().into_owned_sourcemap();

// From a JSON string (zero-copy parse, then detach):
let json = r#"{"version":3,"sources":[],"names":[],"mappings":""}"#;
let owned = OwnedSourceMap::from_json_string(json).unwrap();

// Use the same accessors as SourceMap<'_>:
let _file: Option<&str> = owned.get_file();
let _names: Vec<&str> = owned.get_names().collect();

// Drop into the underlying `&SourceMap<'_>` when needed (e.g. for
// serialization, lookup tables, concat builders):
let _inner: &SourceMap<'_> = owned.as_source_map();
let _json_str = owned.to_json_string();

Implementations§

Source§

impl OwnedSourceMap

Source

pub fn new(inner: SourceMap<'static>) -> OwnedSourceMap

Wrap an already-'static SourceMap.

Source

pub fn as_source_map(&self) -> &SourceMap<'static>

Borrow as &SourceMap<'_> so generic code that works on SourceMap (lookup tables, concat builder, encoder, visualizer) can consume an OwnedSourceMap without an explicit conversion.

Source

pub fn as_source_map_mut(&mut self) -> &mut SourceMap<'static>

Mutable borrow of the inner SourceMap. Useful for set_file etc.

Source

pub fn into_inner(self) -> SourceMap<'static>

Unwrap into the inner SourceMap<'static>.

Source

pub fn from_json(value: JSONSourceMap) -> Result<OwnedSourceMap, Error>

Parse a sourcemap from a JSONSourceMap (already-deserialized JSON).

§Errors

Returns VLQ decode errors.

Source

pub fn from_json_string(value: &str) -> Result<OwnedSourceMap, Error>

Parse a sourcemap from a JSON string. Uses the zero-copy borrowed- deserialization path internally, then detaches to 'static so the result outlives value.

§Errors

Returns serde_json and VLQ decode errors.

Source

pub fn to_json(&self) -> JSONSourceMap

Source

pub fn to_json_string(&self) -> String

Source

pub fn to_data_url(&self) -> String

Source

pub fn compose(self, input: OwnedSourceMap) -> OwnedSourceMap

Compose this generated source map with the source map for its input.

See SourceMap::compose for composition direction and metadata behavior.

Source

pub fn get_file(&self) -> Option<&str>

Source

pub fn set_file(&mut self, file: &str)

Source

pub fn get_source_root(&self) -> Option<&str>

Source

pub fn get_ignore_list(&self) -> Option<&[u32]>

Source

pub fn set_ignore_list(&mut self, list: Vec<u32>)

Source

pub fn get_debug_id(&self) -> Option<&str>

Source

pub fn set_debug_id(&mut self, debug_id: &str)

Source

pub fn get_names(&self) -> impl Iterator<Item = &str>

Source

pub fn get_sources(&self) -> impl Iterator<Item = &str>

Source

pub fn set_sources<S, I>(&mut self, sources: I)
where S: AsRef<str>, I: IntoIterator<Item = S>,

Source

pub fn get_source_contents(&self) -> impl Iterator<Item = Option<&str>>

Source

pub fn set_source_contents(&mut self, contents: Vec<Option<&str>>)

Source

pub fn get_name(&self, id: u32) -> Option<&str>

Source

pub fn get_source(&self, id: u32) -> Option<&str>

Source

pub fn get_source_content(&self, id: u32) -> Option<&str>

Source

pub fn get_source_and_content(&self, id: u32) -> Option<(&str, &str)>

Source

pub fn get_token(&self, index: u32) -> Option<Token>

Source

pub fn get_tokens(&self) -> impl Iterator<Item = Token>

Source

pub fn get_source_view_token( &self, index: u32, ) -> Option<SourceViewToken<'_, 'static>>

Source

pub fn get_source_view_tokens( &self, ) -> impl Iterator<Item = SourceViewToken<'_, 'static>>

Source

pub fn generate_lookup_table(&self) -> Vec<&[Token]>

Source

pub fn lookup_token( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<Token>

Source

pub fn lookup_source_view_token( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<SourceViewToken<'_, 'static>>

Source

pub fn lookup_token_approx( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<Token>

Source

pub fn lookup_source_view_token_approx( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<SourceViewToken<'_, 'static>>

Source

pub fn into_parts(self) -> SourceMapParts<'static>

Take the inner parts; same as SourceMap::into_parts.

Source

pub fn from_parts(parts: SourceMapParts<'static>) -> OwnedSourceMap

Build from parts; same as SourceMap::from_parts.

Methods from Deref<Target = SourceMap<'static>>§

Source

pub fn to_json(&self) -> JSONSourceMap

Convert SourceMap to vlq sourcemap.

Source

pub fn to_json_string(&self) -> String

Convert SourceMap to vlq sourcemap string.

Source

pub fn to_data_url(&self) -> String

Convert SourceMap to vlq sourcemap data url.

Source

pub fn get_file(&self) -> Option<&str>

Source

pub fn set_file(&mut self, file: &str)

Source

pub fn get_source_root(&self) -> Option<&str>

Source

pub fn get_ignore_list(&self) -> Option<&[u32]>

Source

pub fn set_ignore_list(&mut self, ignore_list: Vec<u32>)

Set ignoreList.

Source

pub fn set_debug_id(&mut self, debug_id: &str)

Source

pub fn get_debug_id(&self) -> Option<&str>

Source

pub fn get_names(&self) -> impl ExactSizeIterator

Source

pub fn set_sources<S, I>(&mut self, sources: I)
where S: AsRef<str>, I: IntoIterator<Item = S>,

Adjust sources.

Source

pub fn get_sources(&self) -> impl ExactSizeIterator

Source

pub fn set_source_contents(&mut self, source_contents: Vec<Option<&str>>)

Adjust source_content.

Source

pub fn get_source_contents(&self) -> impl ExactSizeIterator

Source

pub fn get_token(&self, index: u32) -> Option<Token>

Source

pub fn get_source_view_token( &self, index: u32, ) -> Option<SourceViewToken<'_, 'a>>

Source

pub fn get_tokens(&self) -> impl ExactSizeIterator

Get raw tokens.

Source

pub fn get_source_view_tokens(&self) -> impl ExactSizeIterator

Get source view tokens. See SourceViewToken for more information.

Source

pub fn get_name(&self, id: u32) -> Option<&str>

Source

pub fn get_source(&self, id: u32) -> Option<&str>

Source

pub fn get_source_content(&self, id: u32) -> Option<&str>

Source

pub fn get_source_and_content(&self, id: u32) -> Option<(&str, &str)>

Source

pub fn generate_lookup_table(&self) -> Vec<&[Token]>

Generate a lookup table, it will be used at lookup_token or lookup_source_view_token.

Source

pub fn lookup_token( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<Token>

Lookup a token by line and column, it will used at remapping.

Source

pub fn lookup_source_view_token( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<SourceViewToken<'_, 'a>>

Lookup a token by line and column, it will used at remapping. See SourceViewToken.

Source

pub fn lookup_token_approx( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<Token>

Like lookup_token, but clamps to the line’s first token when col falls before it, instead of returning None.

lookup_token returns the greatest token with destination <= (line, col), so a query before a line’s first token yields None. That is correct for a plain position lookup, but it drops mappings when composing sourcemaps — e.g. remapping a token whose column lands before the previous map’s first token on that line (a line indented past column 0). Clamping to the nearest token keeps the mapping, matching Rollup’s collapseSourcemaps traceSegment. An empty line (or a line past the end of the table) still returns None.

Source

pub fn lookup_source_view_token_approx( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<SourceViewToken<'_, 'a>>

Trait Implementations§

Source§

impl Clone for OwnedSourceMap

Source§

fn clone(&self) -> OwnedSourceMap

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OwnedSourceMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for OwnedSourceMap

Source§

fn default() -> OwnedSourceMap

Returns the “default value” for a type. Read more
Source§

impl Deref for OwnedSourceMap

Source§

type Target = SourceMap<'static>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &<OwnedSourceMap as Deref>::Target

Dereferences the value.
Source§

impl DerefMut for OwnedSourceMap

Source§

fn deref_mut(&mut self) -> &mut <OwnedSourceMap as Deref>::Target

Mutably dereferences the value.
Source§

impl From<OwnedSourceMap> for SourceMap<'static>

Source§

fn from(owned: OwnedSourceMap) -> SourceMap<'static>

Converts to this type from the input type.
Source§

impl From<SourceMap<'static>> for OwnedSourceMap

Source§

fn from(inner: SourceMap<'static>) -> OwnedSourceMap

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.