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
impl OwnedSourceMap
Sourcepub fn new(inner: SourceMap<'static>) -> OwnedSourceMap
pub fn new(inner: SourceMap<'static>) -> OwnedSourceMap
Wrap an already-'static SourceMap.
Sourcepub fn as_source_map(&self) -> &SourceMap<'static>
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.
Sourcepub fn as_source_map_mut(&mut self) -> &mut SourceMap<'static>
pub fn as_source_map_mut(&mut self) -> &mut SourceMap<'static>
Mutable borrow of the inner SourceMap. Useful for set_file etc.
Sourcepub fn into_inner(self) -> SourceMap<'static>
pub fn into_inner(self) -> SourceMap<'static>
Unwrap into the inner SourceMap<'static>.
Sourcepub fn from_json(value: JSONSourceMap) -> Result<OwnedSourceMap, Error>
pub fn from_json(value: JSONSourceMap) -> Result<OwnedSourceMap, Error>
Parse a sourcemap from a JSONSourceMap (already-deserialized JSON).
§Errors
Returns VLQ decode errors.
Sourcepub fn from_json_string(value: &str) -> Result<OwnedSourceMap, Error>
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.
pub fn to_json(&self) -> JSONSourceMap
pub fn to_json_string(&self) -> String
pub fn to_data_url(&self) -> String
Sourcepub fn compose(self, input: OwnedSourceMap) -> OwnedSourceMap
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.
pub fn get_file(&self) -> Option<&str>
pub fn set_file(&mut self, file: &str)
pub fn get_source_root(&self) -> Option<&str>
pub fn get_ignore_list(&self) -> Option<&[u32]>
pub fn set_ignore_list(&mut self, list: Vec<u32>)
pub fn get_debug_id(&self) -> Option<&str>
pub fn set_debug_id(&mut self, debug_id: &str)
pub fn get_names(&self) -> impl Iterator<Item = &str>
pub fn get_sources(&self) -> impl Iterator<Item = &str>
pub fn set_sources<S, I>(&mut self, sources: I)
pub fn get_source_contents(&self) -> impl Iterator<Item = Option<&str>>
pub fn set_source_contents(&mut self, contents: Vec<Option<&str>>)
pub fn get_name(&self, id: u32) -> Option<&str>
pub fn get_source(&self, id: u32) -> Option<&str>
pub fn get_source_content(&self, id: u32) -> Option<&str>
pub fn get_source_and_content(&self, id: u32) -> Option<(&str, &str)>
pub fn get_token(&self, index: u32) -> Option<Token>
pub fn get_tokens(&self) -> impl Iterator<Item = Token>
pub fn get_source_view_token( &self, index: u32, ) -> Option<SourceViewToken<'_, 'static>>
pub fn get_source_view_tokens( &self, ) -> impl Iterator<Item = SourceViewToken<'_, 'static>>
pub fn generate_lookup_table(&self) -> Vec<&[Token]>
pub fn lookup_token( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<Token>
pub fn lookup_source_view_token( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<SourceViewToken<'_, 'static>>
pub fn lookup_token_approx( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<Token>
pub fn lookup_source_view_token_approx( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<SourceViewToken<'_, 'static>>
Sourcepub fn into_parts(self) -> SourceMapParts<'static>
pub fn into_parts(self) -> SourceMapParts<'static>
Take the inner parts; same as SourceMap::into_parts.
Sourcepub fn from_parts(parts: SourceMapParts<'static>) -> OwnedSourceMap
pub fn from_parts(parts: SourceMapParts<'static>) -> OwnedSourceMap
Build from parts; same as SourceMap::from_parts.
Methods from Deref<Target = SourceMap<'static>>§
Sourcepub fn to_json(&self) -> JSONSourceMap
pub fn to_json(&self) -> JSONSourceMap
Convert SourceMap to vlq sourcemap.
Sourcepub fn to_json_string(&self) -> String
pub fn to_json_string(&self) -> String
Convert SourceMap to vlq sourcemap string.
Sourcepub fn to_data_url(&self) -> String
pub fn to_data_url(&self) -> String
Convert SourceMap to vlq sourcemap data url.
pub fn get_file(&self) -> Option<&str>
pub fn set_file(&mut self, file: &str)
pub fn get_source_root(&self) -> Option<&str>
pub fn get_ignore_list(&self) -> Option<&[u32]>
Sourcepub fn set_ignore_list(&mut self, ignore_list: Vec<u32>)
pub fn set_ignore_list(&mut self, ignore_list: Vec<u32>)
Set ignoreList.
pub fn set_debug_id(&mut self, debug_id: &str)
pub fn get_debug_id(&self) -> Option<&str>
pub fn get_names(&self) -> impl ExactSizeIterator
Sourcepub fn set_sources<S, I>(&mut self, sources: I)
pub fn set_sources<S, I>(&mut self, sources: I)
Adjust sources.
pub fn get_sources(&self) -> impl ExactSizeIterator
Sourcepub fn set_source_contents(&mut self, source_contents: Vec<Option<&str>>)
pub fn set_source_contents(&mut self, source_contents: Vec<Option<&str>>)
Adjust source_content.
pub fn get_source_contents(&self) -> impl ExactSizeIterator
pub fn get_token(&self, index: u32) -> Option<Token>
pub fn get_source_view_token( &self, index: u32, ) -> Option<SourceViewToken<'_, 'a>>
Sourcepub fn get_tokens(&self) -> impl ExactSizeIterator
pub fn get_tokens(&self) -> impl ExactSizeIterator
Get raw tokens.
Sourcepub fn get_source_view_tokens(&self) -> impl ExactSizeIterator
pub fn get_source_view_tokens(&self) -> impl ExactSizeIterator
Get source view tokens. See SourceViewToken for more information.
pub fn get_name(&self, id: u32) -> Option<&str>
pub fn get_source(&self, id: u32) -> Option<&str>
pub fn get_source_content(&self, id: u32) -> Option<&str>
pub fn get_source_and_content(&self, id: u32) -> Option<(&str, &str)>
Sourcepub fn generate_lookup_table(&self) -> Vec<&[Token]>
pub fn generate_lookup_table(&self) -> Vec<&[Token]>
Generate a lookup table, it will be used at lookup_token or lookup_source_view_token.
Sourcepub fn lookup_token(
&self,
lookup_table: &[&[Token]],
line: u32,
col: u32,
) -> Option<Token>
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.
Sourcepub fn lookup_source_view_token(
&self,
lookup_table: &[&[Token]],
line: u32,
col: u32,
) -> Option<SourceViewToken<'_, 'a>>
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.
Sourcepub fn lookup_token_approx(
&self,
lookup_table: &[&[Token]],
line: u32,
col: u32,
) -> Option<Token>
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.
Sourcepub fn lookup_source_view_token_approx(
&self,
lookup_table: &[&[Token]],
line: u32,
col: u32,
) -> Option<SourceViewToken<'_, 'a>>
pub fn lookup_source_view_token_approx( &self, lookup_table: &[&[Token]], line: u32, col: u32, ) -> Option<SourceViewToken<'_, 'a>>
The SourceViewToken counterpart of lookup_token_approx.
Trait Implementations§
Source§impl Clone for OwnedSourceMap
impl Clone for OwnedSourceMap
Source§fn clone(&self) -> OwnedSourceMap
fn clone(&self) -> OwnedSourceMap
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more