Skip to main content

Crate srcmap_scopes

Crate srcmap_scopes 

Source
Expand description

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.

§Examples

use srcmap_scopes::{
    decode_scopes, encode_scopes, Binding, CallSite, GeneratedRange,
    OriginalScope, Position, ScopeInfo,
};

// Build scope info
let info = ScopeInfo {
    scopes: vec![Some(OriginalScope {
        start: Position { line: 0, column: 0 },
        end: Position { line: 5, column: 0 },
        name: None,
        kind: Some("global".to_string()),
        is_stack_frame: false,
        variables: vec!["x".to_string()],
        children: vec![],
    })],
    ranges: vec![GeneratedRange {
        start: Position { line: 0, column: 0 },
        end: Position { line: 5, column: 0 },
        is_stack_frame: false,
        is_hidden: false,
        definition: Some(0),
        call_site: None,
        bindings: vec![Binding::Expression("_x".to_string())],
        children: vec![],
    }],
};

// Encode
let mut names = vec!["global".to_string(), "x".to_string(), "_x".to_string()];
let encoded = encode_scopes(&info, &mut names);
assert!(!encoded.is_empty());

// Decode
let decoded = decode_scopes(&encoded, &names, 1).unwrap();
assert_eq!(decoded.scopes.len(), 1);
assert!(decoded.scopes[0].is_some());

Structs§

CallSite
A call site in original source code (for inlined functions).
GeneratedRange
A generated range in the output code.
OriginalScope
An original scope from authored source code.
Position
A 0-based position in source code.
ScopeInfo
Decoded scope information from a source map.
SubRangeBinding
A sub-range binding within a generated range.

Enums§

Binding
A binding expression for a variable in a generated range.
ScopesError
Errors during scopes decoding.

Functions§

decode_scopes
Decode a scopes string into structured scope information.
encode_scopes
Encode scope information into a VLQ-encoded scopes string.