srcmap-remapping
Source map concatenation and composition/remapping for Rust.
Merges or chains source maps from multiple build steps into a single map. Drop-in Rust equivalent of @ampproject/remapping.
Install
[]
= "0.2"
Usage
Concatenation
Merge source maps from multiple bundled files into one, adjusting line offsets. Used by bundlers (esbuild, Rollup, Webpack).
use ConcatBuilder;
use SourceMap;
let map_a = from_json.unwrap;
let map_b = from_json.unwrap;
let mut builder = new;
builder.add_map; // a.js starts at line 0
builder.add_map; // b.js starts at line 100
let result = builder.build;
Composition / Remapping
Chain source maps through multiple transforms (e.g. TypeScript -> JavaScript -> minified) into a single map pointing to the original sources.
use remap;
use SourceMap;
let minified_map = from_json.unwrap;
let result = remap;
// result now maps minified output directly to TypeScript sources
API
Concatenation
| Method | Description |
|---|---|
ConcatBuilder::new(file) -> Self |
Create a new concatenation builder |
builder.add_map(sourcemap, line_offset) |
Add a source map at the given line offset |
builder.build() -> SourceMap |
Serialize the current state as a decoded SourceMap |
builder.to_json() -> String |
Serialize the current state as a JSON string |
Composition
| Function | Description |
|---|---|
remap(outer, loader) -> SourceMap |
Compose through upstream maps resolved by loader |
remap_streaming(iter, sources, names, sources_content, ignore_list, file, loader) -> SourceMap |
Streaming variant — avoids materializing the outer map |
The loader function receives each source filename and returns Option<SourceMap>. Return Some to trace through an upstream map, or None to keep the source as-is.
remap_streaming accepts a MappingsIter (lazy VLQ iterator) and uses StreamingGenerator for on-the-fly encoding — 15-20% faster than remap for large maps.
Features
- Source and name deduplication across concatenated maps
sourcesContentmerging from all inputsignoreListpropagation through concatenation- Name resolution prefers upstream names over outer names
- Lazy loading via the
loadercallback — only loads maps that are actually referenced - Range mapping preservation through both concatenation and composition
- Streaming composition via
remap_streamingfor reduced-allocation pipelines
Part of srcmap
See also:
srcmap-sourcemap- Parser and consumersrcmap-generator- Source map buildersrcmap-codec- VLQ encode/decode
License
MIT