Skip to main content

SourceMapBuilder

Struct SourceMapBuilder 

Source
pub struct SourceMapBuilder { /* private fields */ }
Expand description

Builder for incrementally constructing source maps.

§Example

use oak_source_map::SourceMapBuilder;

let mut builder = SourceMapBuilder::new();

// Add a source file
let source_idx = builder.add_source("input.ts");

// Add mappings
builder.add_mapping(0, 0, Some(source_idx), Some(0), Some(0), None);
builder.add_mapping(0, 10, Some(source_idx), Some(0), Some(10), None);

// Build the final source map
let source_map = builder.build();

Implementations§

Source§

impl SourceMapBuilder

Source

pub fn new() -> Self

Creates a new source map builder.

Source

pub fn file(self, file: impl Into<String>) -> Self

Sets the output file name.

Source

pub fn source_root(self, root: impl Into<String>) -> Self

Sets the source root.

Source

pub fn add_source(&mut self, source: impl Into<String>) -> u32

Adds a source file and returns its index.

Source

pub fn set_source_content(&mut self, index: u32, content: impl Into<String>)

Sets the content for a source file.

Source

pub fn add_name(&mut self, name: impl Into<String>) -> u32

Adds a name and returns its index.

Source

pub fn add_mapping( &mut self, generated_line: u32, generated_column: u32, source_index: Option<u32>, original_line: Option<u32>, original_column: Option<u32>, name_index: Option<u32>, )

Adds a mapping.

All line and column values are 0-indexed.

Source

pub fn add_segment( &mut self, generated_line: u32, generated_column: u32, source: Option<&str>, original_line: Option<u32>, original_column: Option<u32>, name: Option<&str>, )

Adds a segment (more convenient API for simple cases).

Source

pub fn build(self) -> SourceMap

Builds the final source map.

Trait Implementations§

Source§

impl Debug for SourceMapBuilder

Source§

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

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

impl Default for SourceMapBuilder

Source§

fn default() -> SourceMapBuilder

Returns the “default value” for a type. Read more

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<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.