Skip to main content

swc_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 swc_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
44//! is the current list of feature flags:
45//!
46//! * `ram_bundle`: turns on RAM bundle support
47pub use crate::{
48    builder::SourceMapBuilder,
49    decoder::{decode, decode_data_url, decode_slice},
50    detector::{
51        is_sourcemap, is_sourcemap_slice, locate_sourcemap_reference,
52        locate_sourcemap_reference_slice, SourceMapRef,
53    },
54    errors::{Error, Result},
55    hermes::SourceMapHermes,
56    sourceview::SourceView,
57    types::{
58        DecodedMap, NameIter, RawToken, RewriteOptions, SourceContentsIter, SourceIter, SourceMap,
59        SourceMapIndex, SourceMapSection, SourceMapSectionIter, Token, TokenIter,
60    },
61    utils::make_relative_path,
62};
63
64mod builder;
65mod decoder;
66mod detector;
67mod encoder;
68mod errors;
69mod hermes;
70mod js_identifiers;
71mod jsontypes;
72pub mod lazy;
73mod sourceview;
74mod types;
75mod utils;
76
77#[cfg(feature = "ram_bundle")]
78pub mod ram_bundle;
79pub mod vlq;