swc_common::source_map

Struct SourceFile

source
pub struct SourceFile {
    pub name: FileName,
    pub name_was_remapped: bool,
    pub unmapped_path: Option<FileName>,
    pub crate_of_origin: u32,
    pub src: Lrc<String>,
    pub src_hash: u128,
    pub start_pos: BytePos,
    pub end_pos: BytePos,
    pub lines: Vec<BytePos>,
    pub multibyte_chars: Vec<MultiByteChar>,
    pub non_narrow_chars: Vec<NonNarrowChar>,
    pub name_hash: u128,
}
Expand description

A single source in the SourceMap.

Fields§

§name: FileName

The name of the file that the source came from. Source that doesn’t originate from files has names between angle brackets by convention, e.g. <anon>

§name_was_remapped: bool

True if the name field above has been modified by --remap-path-prefix

§unmapped_path: Option<FileName>

The unmapped path of the file that the source came from. Set to None if the SourceFile was imported from an external crate.

§crate_of_origin: u32

Indicates which crate this SourceFile was imported from.

§src: Lrc<String>

The complete source code

§src_hash: u128

The source code’s hash

§start_pos: BytePos

The start position of this source in the SourceMap

§end_pos: BytePos

The end position of this source in the SourceMap

§lines: Vec<BytePos>

Locations of lines beginnings in the source code

§multibyte_chars: Vec<MultiByteChar>

Locations of multi-byte characters in the source code

§non_narrow_chars: Vec<NonNarrowChar>

Width of characters that are not narrow in the source code

§name_hash: u128

A hash of the filename, used for speeding up the incr. comp. hashing.

Implementations§

source§

impl SourceFile

source

pub fn new( name: FileName, name_was_remapped: bool, unmapped_path: FileName, src: String, start_pos: BytePos, ) -> SourceFile

source

pub fn new_from( name: FileName, name_was_remapped: bool, unmapped_path: FileName, src: Lrc<String>, start_pos: BytePos, ) -> SourceFile

src should not have UTF8 BOM

source

pub fn line_begin_pos(&self, pos: BytePos) -> BytePos

Return the BytePos of the beginning of the current line.

source

pub fn get_line(&self, line_number: usize) -> Option<Cow<'_, str>>

Get a line from the list of pre-computed line-beginnings. The line number here is 0-based.

source

pub fn is_real_file(&self) -> bool

source

pub fn byte_length(&self) -> u32

source

pub fn count_lines(&self) -> usize

source

pub fn lookup_line(&self, pos: BytePos) -> Option<usize>

Find the line containing the given position. The return value is the index into the lines array of this SourceFile, not the 1-based line number. If the source_file is empty or the position is located before the first line, None is returned.

source

pub fn line_bounds(&self, line_index: usize) -> (BytePos, BytePos)

source

pub fn contains(&self, byte_pos: BytePos) -> bool

Trait Implementations§

source§

impl Clone for SourceFile

source§

fn clone(&self) -> SourceFile

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SourceFile

source§

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

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

impl<'a> From<&'a SourceFile> for StringInput<'a>

Creates an Input from SourceFile. This is an alias for

   StringInput::new(&fm.src, fm.start_pos, fm.end_pos)
source§

fn from(fm: &'a SourceFile) -> Self

Converts to this type from the input type.

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> ErasedDestructor for T
where T: 'static,

source§

impl<T> MaybeSendSync for T