Vendor things
This commit is contained in:
parent
5deceec006
commit
977e3c17e5
19434 changed files with 10682014 additions and 0 deletions
38
third-party/vendor/sourcemap/examples/read.rs
vendored
Normal file
38
third-party/vendor/sourcemap/examples/read.rs
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::Read;
|
||||
|
||||
use sourcemap::{decode, DecodedMap, RewriteOptions, SourceMap};
|
||||
|
||||
fn load_from_reader<R: Read>(mut rdr: R) -> SourceMap {
|
||||
match decode(&mut rdr).unwrap() {
|
||||
DecodedMap::Regular(sm) => sm,
|
||||
DecodedMap::Index(idx) => idx
|
||||
.flatten_and_rewrite(&RewriteOptions {
|
||||
load_local_source_contents: true,
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap(),
|
||||
_ => panic!("unexpected sourcemap format"),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<_> = env::args().collect();
|
||||
let mut f = fs::File::open(&args[1]).unwrap();
|
||||
let sm = load_from_reader(&mut f);
|
||||
|
||||
let line = if args.len() > 2 {
|
||||
args[2].parse::<u32>().unwrap()
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let column = if args.len() > 3 {
|
||||
args[3].parse::<u32>().unwrap()
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let token = sm.lookup_token(line, column).unwrap(); // line-number and column
|
||||
println!("token: {token}");
|
||||
}
|
||||
49
third-party/vendor/sourcemap/examples/rewrite.rs
vendored
Normal file
49
third-party/vendor/sourcemap/examples/rewrite.rs
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
|
||||
use sourcemap::{decode, DecodedMap, RewriteOptions, SourceMap};
|
||||
|
||||
fn test(sm: &SourceMap) {
|
||||
for (src_id, source) in sm.sources().enumerate() {
|
||||
let path = Path::new(source);
|
||||
if path.is_file() {
|
||||
let mut f = fs::File::open(path).unwrap();
|
||||
let mut contents = String::new();
|
||||
if f.read_to_string(&mut contents).ok().is_none() {
|
||||
continue;
|
||||
}
|
||||
if Some(contents.as_str()) != sm.get_source_contents(src_id as u32) {
|
||||
println!(" !!! {source}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn load_from_reader<R: Read>(mut rdr: R) -> SourceMap {
|
||||
match decode(&mut rdr).unwrap() {
|
||||
DecodedMap::Regular(sm) => sm,
|
||||
DecodedMap::Index(idx) => idx
|
||||
.flatten_and_rewrite(&RewriteOptions {
|
||||
load_local_source_contents: true,
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap(),
|
||||
_ => panic!("unexpected sourcemap format"),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<_> = env::args().collect();
|
||||
let mut f = fs::File::open(&args[1]).unwrap();
|
||||
let sm = load_from_reader(&mut f);
|
||||
println!("before dump");
|
||||
test(&sm);
|
||||
|
||||
println!("after dump");
|
||||
let mut json: Vec<u8> = vec![];
|
||||
sm.to_writer(&mut json).unwrap();
|
||||
let sm = load_from_reader(json.as_slice());
|
||||
test(&sm);
|
||||
}
|
||||
61
third-party/vendor/sourcemap/examples/split_ram_bundle.rs
vendored
Normal file
61
third-party/vendor/sourcemap/examples/split_ram_bundle.rs
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
use std::env;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
|
||||
use sourcemap::ram_bundle::{split_ram_bundle, RamBundle, RamBundleType};
|
||||
use sourcemap::SourceMapIndex;
|
||||
|
||||
const USAGE: &str = "
|
||||
Usage:
|
||||
./split_ram_bundle RAM_BUNDLE SOURCEMAP OUT_DIRECTORY
|
||||
|
||||
This example app splits the given RAM bundle and the sourcemap into a set of
|
||||
source files and their sourcemaps.
|
||||
|
||||
Both indexed and file RAM bundles are supported.
|
||||
";
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<_> = env::args().collect();
|
||||
if args.len() < 4 {
|
||||
println!("{USAGE}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let bundle_path = Path::new(&args[1]);
|
||||
let ram_bundle = RamBundle::parse_indexed_from_path(bundle_path)
|
||||
.or_else(|_| RamBundle::parse_unbundle_from_path(bundle_path))?;
|
||||
|
||||
match ram_bundle.bundle_type() {
|
||||
RamBundleType::Indexed => println!("Indexed RAM Bundle detected"),
|
||||
RamBundleType::Unbundle => println!("File RAM Bundle detected"),
|
||||
}
|
||||
|
||||
let sourcemap_file = File::open(&args[2])?;
|
||||
let ism = SourceMapIndex::from_reader(sourcemap_file).unwrap();
|
||||
|
||||
let output_directory = Path::new(&args[3]);
|
||||
if !output_directory.exists() {
|
||||
panic!("Directory {} does not exist!", output_directory.display());
|
||||
}
|
||||
|
||||
println!(
|
||||
"Ouput directory: {}",
|
||||
output_directory.canonicalize()?.display()
|
||||
);
|
||||
let ram_bundle_iter = split_ram_bundle(&ram_bundle, &ism).unwrap();
|
||||
for result in ram_bundle_iter {
|
||||
let (name, sv, sm) = result.unwrap();
|
||||
println!("Writing down source: {name}");
|
||||
fs::write(output_directory.join(name.clone()), sv.source())?;
|
||||
|
||||
let sourcemap_name = format!("{name}.map");
|
||||
println!("Writing down sourcemap: {sourcemap_name}");
|
||||
let out_sm = File::create(output_directory.join(sourcemap_name))?;
|
||||
sm.to_writer(out_sm)?;
|
||||
}
|
||||
println!("Done.");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue