Crate sourcemap [] [src]

This library implements basic processing of JavaScript sourcemaps.

Installation

The crate is called sourcemap and you can depend on it via cargo:

[dependencies]
sourcemap = "*"

If you want to use the git version:

[dependencies.sourcemap]
git = "https://github.com/mitsuhiko/rust-sourcemap.git"

Basic Operation

This crate can load JavaScript sourcemaps from JSON files. It uses serde for parsing of the JSON data. Due to the nature of sourcemaps the entirety of the file must be loaded into memory which can be quite memory intensive.

Usage:

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();
let token = sm.lookup_token(0, 0).unwrap(); // line-number and column
println!("token: {}", token);Run

Structs

RawToken

Represents a raw token

SourceMap

Represents a sourcemap in memory

SourceMapIndex

Represents a sourcemap index in memory

SourceMapSection

Represents a section in a sourcemap index

SourceMapSectionIter

Iterates over all sections in a sourcemap index

Token

Represents a token from a sourcemap

TokenIter

Iterates over all tokens in a sourcemap

Enums

DecodedMap

Represents the result of a decode operation

Error

Represents different failure cases.

SourceMapRef

Represents a reference to a sourcemap

Functions

decode

Decodes a sourcemap or sourcemap index from a reader

decode_data_url

Loads a sourcemap from a data URL.

decode_slice

Decodes a sourcemap or sourcemap index from a byte slice

locate_sourcemap_reference

Locates a sourcemap reference

Type Definitions

Result

Represents results from this library.