pub struct SourceMap { /* private fields */ }
Available on crate feature __common only.
Expand description

The interner for spans.

As most spans are simply stored, we store them as interned 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

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

Calls op with the source code located at sp.

Calls the given closure with the source snippet before the given Span

Return the source snippet as String before the given Span

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.

Extend the given Span to just after the next 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 next 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.

Creates a .map file.

Trait Implementations

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

Return the source snippet as String corresponding to the given Span

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

The archived version of the pointer metadata for this type.

Converts some archived metadata to the pointer metadata for itself.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Deserializes using the given deserializer

Returns the argument unchanged.

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

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Set the foreground color generically Read more

Set the background color generically. Read more

Change the foreground color to black

Change the background color to black

Change the foreground color to red

Change the background color to red

Change the foreground color to green

Change the background color to green

Change the foreground color to yellow

Change the background color to yellow

Change the foreground color to blue

Change the background color to blue

Change the foreground color to magenta

Change the background color to magenta

Change the foreground color to purple

Change the background color to purple

Change the foreground color to cyan

Change the background color to cyan

Change the foreground color to white

Change the background color to white

Change the foreground color to the terminal default

Change the background color to the terminal default

Change the foreground color to bright black

Change the background color to bright black

Change the foreground color to bright red

Change the background color to bright red

Change the foreground color to bright green

Change the background color to bright green

Change the foreground color to bright yellow

Change the background color to bright yellow

Change the foreground color to bright blue

Change the background color to bright blue

Change the foreground color to bright magenta

Change the background color to bright magenta

Change the foreground color to bright purple

Change the background color to bright purple

Change the foreground color to bright cyan

Change the background color to bright cyan

Change the foreground color to bright white

Change the background color to bright white

Make the text bold

Make the text dim

Make the text italicized

Make the text italicized

Make the text blink

Make the text blink (but fast!)

Swap the foreground and background colors

Hide the text

Cross out the text

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more

Set the foreground color to a specific RGB value.

Set the background color to a specific RGB value.

Sets the foreground color to an RGB value.

Sets the background color to an RGB value.

Apply a runtime-determined style

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type for metadata in pointers and references to Self.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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