pub struct SourceMapHermes { /* private fields */ }Expand description
A Hermes-enhanced source map wrapping a regular SourceMap. Adds function scope information from Metro/Hermes extensions.
Implementations§
Source§impl SourceMapHermes
impl SourceMapHermes
Sourcepub fn from_json(json: &str) -> Result<Self, HermesError>
pub fn from_json(json: &str) -> Result<Self, HermesError>
Parse a Hermes source map from JSON.
First parses as a regular source map, then extracts and decodes
the x_facebook_sources, x_facebook_offsets, and
x_metro_module_paths extension fields.
Sourcepub fn into_inner(self) -> SourceMap
pub fn into_inner(self) -> SourceMap
Consume this Hermes source map and return the inner SourceMap.
Sourcepub fn get_function_map(&self, source_idx: u32) -> Option<&HermesFunctionMap>
pub fn get_function_map(&self, source_idx: u32) -> Option<&HermesFunctionMap>
Get the function map for a source by index.
Sourcepub fn get_scope_for_token(&self, line: u32, column: u32) -> Option<&str>
pub fn get_scope_for_token(&self, line: u32, column: u32) -> Option<&str>
Find the enclosing function scope for a position in the generated code.
First resolves the generated position to an original location via the
source map, then looks up the function scope in the correct source’s
function map using the original coordinates. Both line and column
are 0-based.
Sourcepub fn get_original_function_name(&self, line: u32, column: u32) -> Option<&str>
pub fn get_original_function_name(&self, line: u32, column: u32) -> Option<&str>
Get the original function name for a position in the generated code.
First looks up the original position via the source map, then finds the enclosing function scope in the corresponding source’s function map using the original (not generated) coordinates.
Sourcepub fn is_for_ram_bundle(&self) -> bool
pub fn is_for_ram_bundle(&self) -> bool
Check if this source map is for a RAM (Random Access Module) bundle.
Returns true if x_facebook_offsets is present.
Sourcepub fn x_facebook_offsets(&self) -> Option<&[Option<u32>]>
pub fn x_facebook_offsets(&self) -> Option<&[Option<u32>]>
Get the x_facebook_offsets (byte offsets for RAM bundle modules).
Sourcepub fn x_metro_module_paths(&self) -> Option<&[String]>
pub fn x_metro_module_paths(&self) -> Option<&[String]>
Get the x_metro_module_paths (module paths for Metro bundles).
Methods from Deref<Target = SourceMap>§
Sourcepub fn original_position_for(
&self,
line: u32,
column: u32,
) -> Option<OriginalLocation>
pub fn original_position_for( &self, line: u32, column: u32, ) -> Option<OriginalLocation>
Look up the original source position for a generated position.
Both line and column are 0-based.
Returns None if no mapping exists or the mapping has no source.
Sourcepub fn original_position_for_with_bias(
&self,
line: u32,
column: u32,
bias: Bias,
) -> Option<OriginalLocation>
pub fn original_position_for_with_bias( &self, line: u32, column: u32, bias: Bias, ) -> Option<OriginalLocation>
Look up the original source position with a search bias.
Both line and column are 0-based.
GreatestLowerBound: find the closest mapping at or before the column (default)LeastUpperBound: find the closest mapping at or after the column
Sourcepub fn generated_position_for(
&self,
source: &str,
line: u32,
column: u32,
) -> Option<GeneratedLocation>
pub fn generated_position_for( &self, source: &str, line: u32, column: u32, ) -> Option<GeneratedLocation>
Look up the generated position for an original source position.
source is the source filename. line and column are 0-based.
Uses GreatestLowerBound by default (finds closest mapping at or before the position),
matching @jridgewell/trace-mapping’s generatedPositionFor semantics.
Sourcepub fn generated_position_for_with_bias(
&self,
source: &str,
line: u32,
column: u32,
bias: Bias,
) -> Option<GeneratedLocation>
pub fn generated_position_for_with_bias( &self, source: &str, line: u32, column: u32, bias: Bias, ) -> Option<GeneratedLocation>
Look up the generated position with a search bias.
source is the source filename. line and column are 0-based.
GreatestLowerBound: find the closest mapping at or before the position (default)LeastUpperBound: find the closest mapping at or after the position
Sourcepub fn all_generated_positions_for(
&self,
source: &str,
line: u32,
column: u32,
) -> Vec<GeneratedLocation>
pub fn all_generated_positions_for( &self, source: &str, line: u32, column: u32, ) -> Vec<GeneratedLocation>
Find all generated positions for an original source position.
source is the source filename. line and column are 0-based.
Returns all generated positions that map back to this original location.
Sourcepub fn map_range(
&self,
start_line: u32,
start_column: u32,
end_line: u32,
end_column: u32,
) -> Option<MappedRange>
pub fn map_range( &self, start_line: u32, start_column: u32, end_line: u32, end_column: u32, ) -> Option<MappedRange>
Map a generated range to its original range.
Given a generated range (start_line:start_column → end_line:end_column),
maps both endpoints through the source map and returns the original range.
Both endpoints must resolve to the same source file.
Sourcepub fn source(&self, index: u32) -> &str
pub fn source(&self, index: u32) -> &str
Resolve a source index to its filename.
§Panics
Panics if index is out of bounds. Use get_source
for a non-panicking alternative.
Sourcepub fn get_source(&self, index: u32) -> Option<&str>
pub fn get_source(&self, index: u32) -> Option<&str>
Resolve a source index to its filename, returning None if out of bounds.
Sourcepub fn get_name(&self, index: u32) -> Option<&str>
pub fn get_name(&self, index: u32) -> Option<&str>
Resolve a name index to its string, returning None if out of bounds.
Sourcepub fn source_index(&self, name: &str) -> Option<u32>
pub fn source_index(&self, name: &str) -> Option<u32>
Find the source index for a filename.
Sourcepub fn mapping_count(&self) -> usize
pub fn mapping_count(&self) -> usize
Total number of decoded mappings.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Number of generated lines.
Sourcepub fn mappings_for_line(&self, line: u32) -> &[Mapping]
pub fn mappings_for_line(&self, line: u32) -> &[Mapping]
Get all mappings for a generated line (0-based).
Sourcepub fn all_mappings(&self) -> &[Mapping]
pub fn all_mappings(&self) -> &[Mapping]
Iterate all mappings.
Sourcepub fn to_json(&self) -> String
pub fn to_json(&self) -> String
Serialize the source map back to JSON.
Produces a valid source map v3 JSON string that can be written to a file or embedded in a data URL.
Sourcepub fn to_json_with_options(&self, exclude_content: bool) -> String
pub fn to_json_with_options(&self, exclude_content: bool) -> String
Serialize the source map back to JSON with options.
If exclude_content is true, sourcesContent is omitted from the output.
Sourcepub fn encode_mappings(&self) -> String
pub fn encode_mappings(&self) -> String
Encode all mappings back to a VLQ mappings string.
pub fn encode_range_mappings(&self) -> Option<String>
pub fn has_range_mappings(&self) -> bool
pub fn range_mapping_count(&self) -> usize
Sourcepub fn to_writer(&self, writer: impl Write) -> Result<(), Error>
pub fn to_writer(&self, writer: impl Write) -> Result<(), Error>
Serialize the source map JSON to a writer.
Equivalent to calling to_json and writing the result.
The full JSON string is built in memory before writing.
Sourcepub fn to_writer_with_options(
&self,
writer: impl Write,
exclude_content: bool,
) -> Result<(), Error>
pub fn to_writer_with_options( &self, writer: impl Write, exclude_content: bool, ) -> Result<(), Error>
Serialize the source map JSON to a writer with options.
If exclude_content is true, sourcesContent is omitted from the output.
Sourcepub fn to_data_url(&self) -> String
pub fn to_data_url(&self) -> String
Serialize the source map to a data: URL.
Format: data:application/json;base64,<base64-encoded-json>
Sourcepub fn set_source_root(&mut self, source_root: Option<String>)
pub fn set_source_root(&mut self, source_root: Option<String>)
Set or clear the sourceRoot property.
Sourcepub fn set_debug_id(&mut self, debug_id: Option<String>)
pub fn set_debug_id(&mut self, debug_id: Option<String>)
Set or clear the debugId property.
Sourcepub fn set_ignore_list(&mut self, ignore_list: Vec<u32>)
pub fn set_ignore_list(&mut self, ignore_list: Vec<u32>)
Set the ignoreList property.
Sourcepub fn set_sources(&mut self, sources: Vec<Option<String>>)
pub fn set_sources(&mut self, sources: Vec<Option<String>>)
Replace the sources array and rebuild the source index lookup map.