srcmap-scopes
Scopes and variables decoder/encoder for source maps (ECMA-426).
Implements the "Scopes" proposal for source maps, enabling debuggers to reconstruct original scope trees, variable bindings, and inlined function call sites from generated code.
Usage
use ;
// Build scope info
let info = ScopeInfo ;
// Encode to VLQ
let mut names = vec!;
let encoded = encode_scopes;
// Decode back
let decoded = decode_scopes.unwrap;
assert_eq!;
Key types
| Type | Description |
|---|---|
ScopeInfo |
Top-level container: original scopes + generated ranges |
OriginalScope |
A scope in authored source code (tree structure) |
GeneratedRange |
A range in generated output mapped to an original scope |
Binding |
Variable binding: expression, unavailable, or sub-range bindings |
SubRangeBinding |
A sub-range binding within a generated range |
CallSite |
Inlined function call site in original source |
Position |
0-based line/column pair |
ScopesError |
Errors during scopes decoding |
How it works
The scopes format uses tag-based VLQ encoding where each item is prefixed with a tag byte identifying the item type (scope start, scope end, range start, etc.) followed by flags and VLQ-encoded values. This enables efficient serialization of tree-structured scope and range data into a single flat string.
Part of srcmap
Used by srcmap-sourcemap (decode) and srcmap-generator (encode). See the main repo for the full source map SDK.
License
MIT