Skip to main content

remap_chain

Function remap_chain 

Source
pub fn remap_chain(maps: &[&SourceMap]) -> Option<SourceMap>
Expand description

Compose a chain of pre-parsed source maps into a single source map.

Takes a slice of source maps in chain order: the first map is the outermost (final transform), and the last is the innermost (closest to original sources). Each consecutive pair is composed, threading mappings from generated → original.

This is more ergonomic than remap for cases where all maps are already parsed (e.g. Rolldown), since no loader closure is needed.

Returns the composed source map, or None if the slice is empty.

§Examples

use srcmap_remapping::remap_chain;
use srcmap_sourcemap::SourceMap;

let step1 = r#"{"version":3,"file":"inter.js","sources":["original.js"],"names":[],"mappings":"AAAA;AACA"}"#;
let step2 = r#"{"version":3,"file":"output.js","sources":["inter.js"],"names":[],"mappings":"AAAA;AACA"}"#;

let maps: Vec<SourceMap> = vec![
    SourceMap::from_json(step2).unwrap(),
    SourceMap::from_json(step1).unwrap(),
];
let refs: Vec<&SourceMap> = maps.iter().collect();
let result = remap_chain(&refs);
assert!(result.is_some());
let result = result.unwrap();
assert_eq!(result.sources, vec!["original.js"]);