sourcemap/lib.rs
1//! This library implements basic processing of JavaScript sourcemaps.
2//!
3//! # Installation
4//!
5//! The crate is called sourcemap and you can depend on it via cargo:
6//!
7//! ```toml
8//! [dependencies]
9//! sourcemap = "*"
10//! ```
11//!
12//! If you want to use the git version:
13//!
14//! ```toml
15//! [dependencies.sourcemap]
16//! git = "https://github.com/getsentry/rust-sourcemap.git"
17//! ```
18//!
19//! # Basic Operation
20//!
21//! This crate can load JavaScript sourcemaps from JSON files. It uses
22//! `serde` for parsing of the JSON data. Due to the nature of sourcemaps
23//! the entirety of the file must be loaded into memory which can be quite
24//! memory intensive.
25//!
26//! Usage:
27//!
28//! ```rust
29//! use sourcemap::SourceMap;
30//! let input: &[_] = b"{
31//! \"version\":3,
32//! \"sources\":[\"coolstuff.js\"],
33//! \"names\":[\"x\",\"alert\"],
34//! \"mappings\":\"AAAA,GAAIA,GAAI,EACR,IAAIA,GAAK,EAAG,CACVC,MAAM\"
35//! }";
36//! let sm = SourceMap::from_reader(input).unwrap();
37//! let token = sm.lookup_token(0, 0).unwrap(); // line-number and column
38//! println!("token: {}", token);
39//! ```
40//!
41//! # Features
42//!
43//! Functionality of the crate can be turned on and off by feature flags. This is the
44//! current list of feature flags:
45//!
46//! * `ram_bundle`: turns on RAM bundle support
47//!
48#[warn(missing_docs)]
49mod macros;
50
51pub use crate::builder::SourceMapBuilder;
52pub use crate::decoder::{decode, decode_data_url, decode_slice};
53pub use crate::detector::{
54 is_sourcemap, is_sourcemap_slice, locate_sourcemap_reference, locate_sourcemap_reference_slice,
55 SourceMapRef,
56};
57pub use crate::errors::{Error, Result};
58pub use crate::hermes::SourceMapHermes;
59pub use crate::sourceview::SourceView;
60pub use crate::types::{
61 DecodedMap, NameIter, RawToken, RewriteOptions, SourceContentsIter, SourceIter, SourceMap,
62 SourceMapIndex, SourceMapSection, SourceMapSectionIter, Token, TokenIter,
63};
64pub use crate::utils::make_relative_path;
65
66mod builder;
67mod decoder;
68mod detector;
69mod encoder;
70mod errors;
71mod hermes;
72mod js_identifiers;
73mod jsontypes;
74mod sourceview;
75mod types;
76mod utils;
77
78#[cfg(feature = "ram_bundle")]
79pub mod ram_bundle;
80pub mod vlq;