Struct swc_common::source_map::SourceMap [−][src]
pub struct SourceMap { /* fields omitted */ }
Expand description
The interner for spans.
As most spans are simply stored, we store them as interend form.
- Each ast node only stores pointer to actual data (BytePos).
- The pointers (BytePos) can be converted to file name, line and column using this struct.
Note
This struct should be shared. swc_common
uses crate::sync::Lrc, which is
std::rc::Rc or std::sync::Arc, depending on the compile option, for this
purpose.
Note for bundler authors
If you are bundling modules, you should share this struct while parsing modules. Otherwise, you have to implement a code generator which accepts multiple SourceMap.
Implementations
pub fn with_file_loader(
file_loader: Box<dyn FileLoader + Sync + Send>,
path_mapping: FilePathMapping
) -> SourceMap
pub fn source_file_by_stable_id(
&self,
stable_id: StableSourceFileId
) -> Option<Lrc<SourceFile>>
Creates a new source_file. This does not ensure that only one SourceFile exists per file name.
Lookup source information about a BytePos
If the relevant source_file is empty, we don’t return a line number.
Returns Some(span)
, a union of the lhs and rhs span. The lhs must
precede the rhs. If there are gaps between lhs and rhs, the
resulting union will cross these gaps. For this to work, the spans
have to be:
- the ctxt of both spans much match
- the lhs span needs to end on the same line the rhs span begins
- the lhs span must start at or before the rhs span
Return the source snippet as String
corresponding to the given Span
pub fn with_span_to_prev_source<F, Ret>(
&self,
sp: Span,
op: F
) -> Result<Ret, SpanSnippetError> where
F: FnOnce(&str) -> Ret,
pub fn with_span_to_prev_source<F, Ret>(
&self,
sp: Span,
op: F
) -> Result<Ret, SpanSnippetError> where
F: FnOnce(&str) -> Ret,
Calls the given closure with the source snippet before the given Span
Return the source snippet as String
before the given Span
pub fn with_span_to_next_source<F, Ret>(
&self,
sp: Span,
op: F
) -> Result<Ret, SpanSnippetError> where
F: FnOnce(&str) -> Ret,
pub fn with_span_to_next_source<F, Ret>(
&self,
sp: Span,
op: F
) -> Result<Ret, SpanSnippetError> where
F: FnOnce(&str) -> Ret,
Calls the given closure with the source snippet after the given Span
Return the source snippet as String
after the given Span
Extend the given Span
to just after the previous occurrence of c
.
Return the same span if no character could be found or if an error
occurred while retrieving the code snippet.
Extend the given Span
to just after the previous occurrence of pat
when surrounded by whitespace. Return the same span if no character
could be found or if an error occurred while retrieving the code
snippet.
Given a Span
, try to get a shorter span ending before the first
occurrence of c
char
Notes
This method returns a dummy span for a dummy span.
Given a Span
, try to get a shorter span ending just after the first
occurrence of char
c
.
Notes
This method returns a dummy span for a dummy span.
Given a Span
, get a new Span
covering the first token and all its
trailing whitespace or the original Span
.
If sp
points to "let mut x"
, then a span pointing at "let "
will
be returned.
Given a Span
, get a new Span
covering the first token without its
trailing whitespace or the original Span
in case of error.
If sp
points to "let mut x"
, then a span pointing at "let"
will be
returned.
Given a Span
, get a shorter one until predicate
yields false.
Returns a new span representing just the start-point of this span
Returns a new span representing just the end-point of this span
Returns a new span representing the next character after the end-point of this span
For a global BytePos compute the local offset within the containing SourceFile
Take the span of a type parameter in a function signature and try to generate a span for the function name (with generics) and a new snippet for this span with the pointed type parameter as a new local type parameter.
For instance:
// Given span
fn my_function(param: T)
// ^ Original span
// Result
fn my_function(param: T)
// ^^^^^^^^^^^ Generated span with snippet `my_function<T>`
Attention: The method used is very fragile since it essentially duplicates the work of the parser. If you need to use this function or something similar, please consider updating the source_map functions and this function to something more robust.
This is supported on crate feature sourcemap
only.
sourcemap
only.pub fn build_source_map_from(
&self,
mappings: &mut Vec<(BytePos, LineCol)>,
orig: Option<&SourceMap>
) -> SourceMap
This is supported on crate feature sourcemap
only.
pub fn build_source_map_from(
&self,
mappings: &mut Vec<(BytePos, LineCol)>,
orig: Option<&SourceMap>
) -> SourceMap
sourcemap
only.Creates a .map
file.
pub fn build_source_map_with_config(
&self,
mappings: &mut Vec<(BytePos, LineCol)>,
orig: Option<&SourceMap>,
config: impl SourceMapGenConfig
) -> SourceMap
sourcemap
only.Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for SourceMap
impl !UnwindSafe for SourceMap
Blanket Implementations
Mutably borrows from an owned value. Read more
type ForSelf = WithMetadata_<T, T>
type ForSelf = WithMetadata_<T, T>
This is always WithMetadata_<Self, Self>
Gets a reference to a field, determined by offset
. Read more
Gets a muatble reference to a field, determined by offset
. Read more
Gets a const pointer to a field,
the field is determined by offset
. Read more
pub fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
pub fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
Gets a mutable pointer to a field, determined by offset
. Read more
pub fn f_replace<F>(
&mut self,
offset: FieldOffset<S, F, Aligned>,
value: F
) -> F
pub fn f_replace<F>(
&mut self,
offset: FieldOffset<S, F, Aligned>,
value: F
) -> F
Replaces a field (determined by offset
) with value
,
returning the previous value of the field. Read more
Swaps a field (determined by offset
) with the same field in right
. Read more
pub fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> F where
F: Copy,
pub fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> F where
F: Copy,
Gets a copy of a field (determined by offset
).
The field is determined by offset
. Read more
pub fn f_replace<F>(
&mut self,
offset: FieldOffset<S, F, Unaligned>,
value: F
) -> F
pub fn f_replace<F>(
&mut self,
offset: FieldOffset<S, F, Unaligned>,
value: F
) -> F
Replaces a field (determined by offset
) with value
,
returning the previous value of the field. Read more
Swaps a field (determined by offset
) with the same field in right
. Read more
pub fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> F where
F: Copy,
pub fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> F where
F: Copy,
Gets a copy of a field (determined by offset
).
The field is determined by offset
. Read more
impl<T> SelfOps for T where
T: ?Sized,
impl<T> SelfOps for T where
T: ?Sized,
Compares the address of self
with the address of other
. Read more
Emulates the pipeline operator, allowing method syntax in more places. Read more
The same as piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read more
The same as piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
. Read more
Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
Observes the value of self, passing it along unmodified. Useful in long method chains. Read more
Performs a conversion with Into
.
using the turbofish .into_::<_>()
syntax. Read more
Performs a reference to reference conversion with AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more
Performs a mutable reference to mutable reference conversion with AsMut
,
using the turbofish .as_mut_::<_>()
syntax. Read more
unsafe fn transmute_element<T>(self) -> Self::TransmutedPtr where
Self: CanTransmuteElement<T>,
unsafe fn transmute_element<T>(self) -> Self::TransmutedPtr where
Self: CanTransmuteElement<T>,
Transmutes the element type of this pointer.. Read more
impl<T> TypeIdentity for T where
T: ?Sized,
impl<T> TypeIdentity for T where
T: ?Sized,
type Type = T
type Type = T
This is always Self
.
Converts a value back to the original type.
fn as_type(&self) -> &Self::Type
fn as_type(&self) -> &Self::Type
Converts a reference back to the original type.
fn as_type_mut(&mut self) -> &mut Self::Type
fn as_type_mut(&mut self) -> &mut Self::Type
Converts a mutable reference back to the original type.
fn into_type_box(self: Box<Self, Global>) -> Box<Self::Type, Global>
fn into_type_box(self: Box<Self, Global>) -> Box<Self::Type, Global>
Converts a box back to the original type.
fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>
fn into_type_arc(this: Arc<Self>) -> Arc<Self::Type>
Converts an Arc back to the original type. Read more
fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>
fn into_type_rc(this: Rc<Self>) -> Rc<Self::Type>
Converts an Rc back to the original type. Read more
Converts a value back to the original type.
fn from_type_ref(this: &Self::Type) -> &Self
fn from_type_ref(this: &Self::Type) -> &Self
Converts a reference back to the original type.
fn from_type_mut(this: &mut Self::Type) -> &mut Self
fn from_type_mut(this: &mut Self::Type) -> &mut Self
Converts a mutable reference back to the original type.
fn from_type_box(this: Box<Self::Type, Global>) -> Box<Self, Global>
fn from_type_box(this: Box<Self::Type, Global>) -> Box<Self, Global>
Converts a box back to the original type.
fn from_type_arc(this: Arc<Self::Type>) -> Arc<Self>
fn from_type_arc(this: Arc<Self::Type>) -> Arc<Self>
Converts an Arc back to the original type.
fn from_type_rc(this: Rc<Self::Type>) -> Rc<Self>
fn from_type_rc(this: Rc<Self::Type>) -> Rc<Self>
Converts an Rc back to the original type.
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more