Skip to main content

Crate srcmap_generator

Crate srcmap_generator 

Source
Expand description

High-performance source map generator (ECMA-426).

Builds source maps incrementally by adding mappings one at a time. Outputs standard source map v3 JSON.

§Examples

use srcmap_generator::SourceMapGenerator;

fn main() {
    let mut builder = SourceMapGenerator::new(Some("bundle.js".to_string()));

    let src = builder.add_source("src/app.ts");
    builder.set_source_content(src, "const x = 1;".to_string());

    let name = builder.add_name("x");
    builder.add_named_mapping(0, 0, src, 0, 6, name);
    builder.add_mapping(1, 0, src, 1, 0);

    let json = builder.to_json();
    assert!(json.contains(r#""version":3"#));
    assert!(json.contains(r#""sources":["src/app.ts"]"#));
}

Structs§

Mapping
A mapping from a generated position to an original position.
SourceMapGenerator
Builder for creating source maps incrementally.
SourceMapParts
Decomposed source map parts for structured access without JSON serialization.
StreamingGenerator
Source map generator that encodes VLQ on-the-fly.