Skip to main content

SourceMapHermes

Struct SourceMapHermes 

Source
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

Source

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.

Source

pub fn inner(&self) -> &SourceMap

Get a reference to the inner SourceMap.

Source

pub fn into_inner(self) -> SourceMap

Consume this Hermes source map and return the inner SourceMap.

Source

pub fn get_function_map(&self, source_idx: u32) -> Option<&HermesFunctionMap>

Get the function map for a source by index.

Source

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.

Source

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.

Source

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.

Source

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

Get the x_facebook_offsets (byte offsets for RAM bundle modules).

Source

pub fn x_metro_module_paths(&self) -> Option<&[String]>

Get the x_metro_module_paths (module paths for Metro bundles).

Source

pub fn to_json(&self) -> String

Serialize back to JSON, preserving the Facebook extensions.

The inner source map already stores all extension fields (including x_facebook_sources, x_facebook_offsets, x_metro_module_paths) from the original parse, so this delegates directly.

Methods from Deref<Target = SourceMap>§

Source

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.

Source

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
Source

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.

Source

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
Source

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.

Source

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.

Source

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.

Source

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

Resolve a source index to its filename, returning None if out of bounds.

Source

pub fn name(&self, index: u32) -> &str

Resolve a name index to its string.

§Panics

Panics if index is out of bounds. Use get_name for a non-panicking alternative.

Source

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

Resolve a name index to its string, returning None if out of bounds.

Source

pub fn source_index(&self, name: &str) -> Option<u32>

Find the source index for a filename.

Source

pub fn mapping_count(&self) -> usize

Total number of decoded mappings.

Source

pub fn line_count(&self) -> usize

Number of generated lines.

Source

pub fn mappings_for_line(&self, line: u32) -> &[Mapping]

Get all mappings for a generated line (0-based).

Source

pub fn all_mappings(&self) -> &[Mapping]

Iterate all mappings.

Source

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.

Source

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.

Source

pub fn encode_mappings(&self) -> String

Encode all mappings back to a VLQ mappings string.

Source

pub fn encode_range_mappings(&self) -> Option<String>

Source

pub fn has_range_mappings(&self) -> bool

Source

pub fn range_mapping_count(&self) -> usize

Source

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.

Source

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.

Source

pub fn to_data_url(&self) -> String

Serialize the source map to a data: URL.

Format: data:application/json;base64,<base64-encoded-json>

Source

pub fn set_file(&mut self, file: Option<String>)

Set or clear the file property.

Source

pub fn set_source_root(&mut self, source_root: Option<String>)

Set or clear the sourceRoot property.

Source

pub fn set_debug_id(&mut self, debug_id: Option<String>)

Set or clear the debugId property.

Source

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

Set the ignoreList property.

Source

pub fn set_sources(&mut self, sources: Vec<Option<String>>)

Replace the sources array and rebuild the source index lookup map.

Trait Implementations§

Source§

impl Debug for SourceMapHermes

Source§

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

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

impl Deref for SourceMapHermes

Source§

type Target = SourceMap

The resulting type after dereferencing.
Source§

fn deref(&self) -> &SourceMap

Dereferences the value.
Source§

impl DerefMut for SourceMapHermes

Source§

fn deref_mut(&mut self) -> &mut SourceMap

Mutably dereferences the value.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.