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

Represents a sourcemap in memory

This is always represents a regular “non-indexed” sourcemap. Particularly in case the from_reader method is used an index sourcemap will be rejected with an error on reading.

Implementations

Creates a sourcemap from a reader over a JSON stream in UTF-8 format. Optionally a “garbage header” as defined by the sourcemap draft specification is supported. In case an indexed sourcemap is encountered an error is returned.

use sourcemap::SourceMap;
let input: &[_] = b"{
    \"version\":3,
    \"sources\":[\"coolstuff.js\"],
    \"names\":[\"x\",\"alert\"],
    \"mappings\":\"AAAA,GAAIA,GAAI,EACR,IAAIA,GAAK,EAAG,CACVC,MAAM\"
}";
let sm = SourceMap::from_reader(input).unwrap();

While sourcemaps objects permit some modifications, it’s generally not possible to modify tokens after they have been added. For creating sourcemaps from scratch or for general operations for modifying a sourcemap have a look at the SourceMapBuilder.

Writes a sourcemap into a writer.

Note that this operation will generate an equivalent sourcemap to the one that was generated on load however there might be small differences in the generated JSON and layout. For instance sourceRoot will not be set as upon parsing of the sourcemap the sources will already be expanded.

let sm = SourceMap::from_reader(input).unwrap();
let mut output : Vec<u8> = vec![];
sm.to_writer(&mut output).unwrap();

Creates a sourcemap from a reader over a JSON byte slice in UTF-8 format. Optionally a “garbage header” as defined by the sourcemap draft specification is supported. In case an indexed sourcemap is encountered an error is returned.

use sourcemap::SourceMap;
let input: &[_] = b"{
    \"version\":3,
    \"sources\":[\"coolstuff.js\"],
    \"names\":[\"x\",\"alert\"],
    \"mappings\":\"AAAA,GAAIA,GAAI,EACR,IAAIA,GAAK,EAAG,CACVC,MAAM\"
}";
let sm = SourceMap::from_slice(input).unwrap();

Constructs a new sourcemap from raw components.

  • file: an optional filename of the sourcemap
  • tokens: a list of raw tokens
  • names: a vector of names
  • sources a vector of source filenames
  • sources_content optional source contents

Returns the embedded filename in case there is one.

Sets a new value for the file.

Looks up a token by its index.

Returns the number of tokens in the sourcemap.

Returns an iterator over the tokens.

Looks up the closest token to a given 0-indexed line and column.

Given a location, name and minified source file resolve a minified name to an original function name.

This invokes some guesswork and requires access to the original minified source. This will not yield proper results for anonymous functions or functions that do not have clear function names. (For instance it’s recommended that dotted function names are not passed to this function).

Returns the number of sources in the sourcemap.

Looks up a source for a specific index.

Sets a new source value for an index. This cannot add new sources.

This panics if a source is set that does not exist.

Iterates over all sources

Returns the sources content as source view.

Looks up the content for a source.

Sets source contents for a source.

Iterates over all source contents

Returns an iterator over the names.

Returns the number of names in the sourcemap.

Returns true if there are any names in the map.

Looks up a name for a specific index.

Removes all names from the sourcemap.

Returns the number of items in the index

Returns the number of items in the index

This rewrites the sourcemap according to the provided rewrite options.

The default behavior is to just deduplicate the sourcemap, something that automatically takes place. This for instance can be used to slightly compress sourcemaps if certain data is not wanted.

use sourcemap::{SourceMap, RewriteOptions};
let sm = SourceMap::from_slice(input).unwrap();
let new_sm = sm.rewrite(&RewriteOptions {
    with_names: false,
    ..Default::default()
});

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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.

Available on crate feature quote only.

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 resulting type after obtaining ownership.

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

Uses borrowed data to replace owned data, usually by cloning. Read more

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