Struct sourcemap::SourceMap
[−]
[src]
pub struct SourceMap {
// some fields omitted
}Represents a sourcemap in memory
This is always represents a regular "non-indexed" sourcemap. Particularly
in case the from_reader method is used an index sourcemap will be
rejected with an error on reading.
Methods
impl SourceMap[src]
fn from_reader<R: Read>(rdr: R) -> Result<SourceMap>
Creates a sourcemap from a reader over a JSON stream in UTF-8 format. Optionally a "garbage header" as defined by the sourcemap draft specification is supported. In case an indexed sourcemap is encountered an error is returned.
use sourcemap::SourceMap; let input: &[_] = b"{ \"version\":3, \"sources\":[\"coolstuff.js\"], \"names\":[\"x\",\"alert\"], \"mappings\":\"AAAA,GAAIA,GAAI,EACR,IAAIA,GAAK,EAAG,CACVC,MAAM\" }"; let sm = SourceMap::from_reader(input).unwrap();
fn new(version: u32, file: Option<String>, tokens: Vec<RawToken>, index: Vec<(u32, u32, u32)>, names: Vec<String>, sources: Vec<String>, sources_content: Option<Vec<Option<String>>>) -> SourceMap
Constructs a new sourcemap from raw components.
version: the version is typically3which is the current darft versionfile: an optional filename of the sourcemaptokens: a list of raw tokensindex: a sorted mapping of line and column to token indexnames: a vector of namessourcesa vector of source filenamessources_contentoptional source contents
fn get_version(&self) -> u32
Returns the version of the sourcemap.
fn get_file(&self) -> Option<&str>
Returns the embedded filename in case there is one.
fn get_token<'a>(&'a self, idx: u32) -> Option<Token<'a>>
Looks up a token by its index.
fn get_token_count(&self) -> u32
Returns the number of tokens in the sourcemap.
fn tokens<'a>(&'a self) -> TokenIter<'a>
Returns an iterator over the tokens.
fn lookup_token<'a>(&'a self, line: u32, col: u32) -> Option<Token<'a>>
Looks up the closest token to a given line and column.
fn get_source_count(&self) -> u32
Returns the number of sources in the sourcemap.
fn get_source(&self, idx: u32) -> Option<&str>
Looks up a source for a specific index.
fn get_source_contents(&self, idx: u32) -> Option<&str>
Looks up the content for a source.
fn get_name_count(&self) -> u32
Returns the number of names in the sourcemap.
fn get_name(&self, idx: u32) -> Option<&str>
Looks up a name for a specific index.