Expand description
High-performance source map parser and consumer (ECMA-426).
Parses source map JSON and provides O(log n) position lookups. Uses a flat, cache-friendly representation internally.
§Examples
use srcmap_sourcemap::SourceMap;
let json = r#"{"version":3,"sources":["input.js"],"names":[],"mappings":"AAAA;AACA"}"#;
let sm = SourceMap::from_json(json).unwrap();
// Look up original position for generated line 0, column 0
let loc = sm.original_position_for(0, 0).unwrap();
assert_eq!(sm.source(loc.source), "input.js");
assert_eq!(loc.line, 0);
assert_eq!(loc.column, 0);
// Reverse lookup
let pos = sm.generated_position_for("input.js", 0, 0).unwrap();
assert_eq!(pos.line, 0);
assert_eq!(pos.column, 0);Re-exports§
pub use source_view::SourceView;
Modules§
- js_
identifiers - JavaScript identifier validation utilities.
- source_
view - Efficient source view with lazy line caching and UTF-16 column support.
- utils
- Utility functions for source map path resolution, validation, rewriting, and encoding.
Structs§
- Generated
Location - Result of a
SourceMap::generated_position_forlookup. - Lazy
Source Map - A lazily-decoded source map that defers VLQ mappings decoding until needed.
- Mapped
Range - A mapped range: original start/end positions for a generated range.
- Mapping
- A single decoded mapping entry. Compact at 28 bytes (6 × u32 + bool with padding).
- Mappings
Iter - Lazy iterator over VLQ-encoded source map mappings.
- Original
Location - Result of an
SourceMap::original_position_forlookup. - RawSource
MapLite - Lightweight version that skips sourcesContent allocation. Used by WASM bindings where sourcesContent is kept JS-side.
- Source
Map - A fully-parsed source map with O(log n) position lookups.
- Source
MapBuilder - Builder for incrementally constructing a
SourceMapfrom iterators.
Enums§
- Bias
- Search bias for position lookups.
- Parse
Error - Errors that can occur during source map parsing.
- Source
Mapping Url - Result of parsing a sourceMappingURL reference.
Functions§
- parse_
source_ mapping_ url - Extract the sourceMappingURL from generated source code.
- resolve_
sources - Resolve source filenames by applying
source_rootprefix and replacingNonewith empty string. - validate_
deep - Validate a source map with deep structural checks.