mirror of
https://github.com/hanzoai/swc.git
synced 2026-10-30 19:42:53 +00:00
## Summary - move inlined `swc_sourcemap` into `crates/swc_sourcemap` - keep only source-oriented files (`Cargo.toml` + `src/**`), removing docs/tests/examples/CI scripts from the imported repository snapshot - wire workspace dependency directly via path in root `Cargo.toml` - remove previous `vendor` patch override ## Notes I'm doing this because I want to implement the source map scoping proposal
21 lines
774 B
Rust
21 lines
774 B
Rust
use swc_sourcemap::SourceMapBuilder;
|
|
|
|
#[test]
|
|
fn test_builder_into_sourcemap() {
|
|
let mut builder = SourceMapBuilder::new(None);
|
|
builder.set_source_root(Some("/foo/bar"));
|
|
builder.add_source("baz.js".into());
|
|
builder.add_name("x".into());
|
|
builder.add_to_ignore_list(0);
|
|
|
|
let sm = builder.into_sourcemap();
|
|
assert_eq!(sm.get_source_root().map(|v| &**v), Some("/foo/bar"));
|
|
assert_eq!(sm.get_source(0).map(|v| &**v), Some("/foo/bar/baz.js"));
|
|
assert_eq!(sm.get_name(0).map(|v| &**v), Some("x"));
|
|
|
|
let expected = br#"{"version":3,"sources":["baz.js"],"sourceRoot":"/foo/bar","names":["x"],"mappings":"","ignoreList":[0]}"#;
|
|
let mut output: Vec<u8> = vec![];
|
|
sm.to_writer(&mut output).unwrap();
|
|
assert_eq!(output, expected);
|
|
}
|