Struct sourcemap::SourceMapBuilder
source · pub struct SourceMapBuilder { /* private fields */ }
Expand description
Helper for sourcemap generation
This helper exists because generating and modifying SourceMap
objects is generally not very comfortable. As a general aid this
type can help.
Implementations§
source§impl SourceMapBuilder
impl SourceMapBuilder
sourcepub fn new(file: Option<&str>) -> SourceMapBuilder
pub fn new(file: Option<&str>) -> SourceMapBuilder
Creates a new source map builder and sets the file.
sourcepub fn set_file<T: Into<String>>(&mut self, value: Option<T>)
pub fn set_file<T: Into<String>>(&mut self, value: Option<T>)
Sets the file for the sourcemap (optional)
sourcepub fn set_source_root<T: Into<String>>(&mut self, value: Option<T>)
pub fn set_source_root<T: Into<String>>(&mut self, value: Option<T>)
Sets a new value for the source_root.
sourcepub fn get_source_root(&self) -> Option<&str>
pub fn get_source_root(&self) -> Option<&str>
Returns the embedded source_root in case there is one.
sourcepub fn add_source(&mut self, src: &str) -> u32
pub fn add_source(&mut self, src: &str) -> u32
Registers a new source with the builder and returns the source ID.
sourcepub fn set_source(&mut self, src_id: u32, src: &str)
pub fn set_source(&mut self, src_id: u32, src: &str)
Changes the source name for an already set source.
sourcepub fn get_source(&self, src_id: u32) -> Option<&str>
pub fn get_source(&self, src_id: u32) -> Option<&str>
Looks up a source name for an ID.
sourcepub fn set_source_contents(&mut self, src_id: u32, contents: Option<&str>)
pub fn set_source_contents(&mut self, src_id: u32, contents: Option<&str>)
Sets the source contents for an already existing source.
sourcepub fn get_source_contents(&self, src_id: u32) -> Option<&str>
pub fn get_source_contents(&self, src_id: u32) -> Option<&str>
Returns the current source contents for a source.
sourcepub fn has_source_contents(&self, src_id: u32) -> bool
pub fn has_source_contents(&self, src_id: u32) -> bool
Checks if a given source ID has source contents available.
sourcepub fn load_local_source_contents(
&mut self,
base_path: Option<&Path>
) -> Result<usize>
pub fn load_local_source_contents(
&mut self,
base_path: Option<&Path>
) -> Result<usize>
Loads source contents from locally accessible files if referenced accordingly. Returns the number of loaded source contents
sourcepub fn add_name(&mut self, name: &str) -> u32
pub fn add_name(&mut self, name: &str) -> u32
Registers a name with the builder and returns the name ID.
sourcepub fn add(
&mut self,
dst_line: u32,
dst_col: u32,
src_line: u32,
src_col: u32,
source: Option<&str>,
name: Option<&str>
) -> RawToken
pub fn add(
&mut self,
dst_line: u32,
dst_col: u32,
src_line: u32,
src_col: u32,
source: Option<&str>,
name: Option<&str>
) -> RawToken
Adds a new mapping to the builder.
sourcepub fn add_raw(
&mut self,
dst_line: u32,
dst_col: u32,
src_line: u32,
src_col: u32,
source: Option<u32>,
name: Option<u32>
) -> RawToken
pub fn add_raw(
&mut self,
dst_line: u32,
dst_col: u32,
src_line: u32,
src_col: u32,
source: Option<u32>,
name: Option<u32>
) -> RawToken
Adds a new mapping to the builder.
sourcepub fn add_token(&mut self, token: &Token<'_>, with_name: bool) -> RawToken
pub fn add_token(&mut self, token: &Token<'_>, with_name: bool) -> RawToken
Shortcut for adding a new mapping based of an already existing token, optionally removing the name.
sourcepub fn strip_prefixes<S: AsRef<str>>(&mut self, prefixes: &[S])
pub fn strip_prefixes<S: AsRef<str>>(&mut self, prefixes: &[S])
Strips common prefixes from the sources in the builder
sourcepub fn into_sourcemap(self) -> SourceMap
pub fn into_sourcemap(self) -> SourceMap
Converts the builder into a sourcemap.