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
72 lines
1.8 KiB
Rust
72 lines
1.8 KiB
Rust
use swc_sourcemap::{is_sourcemap_slice, locate_sourcemap_reference, SourceMapRef};
|
|
|
|
#[test]
|
|
fn test_basic_locate() {
|
|
let input: &[_] = b"foo();\nbar();\n//# sourceMappingURL=foo.js";
|
|
assert_eq!(
|
|
locate_sourcemap_reference(input).unwrap(),
|
|
Some(SourceMapRef::Ref("foo.js".into()))
|
|
);
|
|
assert_eq!(
|
|
locate_sourcemap_reference(input)
|
|
.unwrap()
|
|
.unwrap()
|
|
.get_url(),
|
|
"foo.js"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_legacy_locate() {
|
|
let input: &[_] = b"foo();\nbar();\n//@ sourceMappingURL=foo.js";
|
|
assert_eq!(
|
|
locate_sourcemap_reference(input).unwrap(),
|
|
Some(SourceMapRef::LegacyRef("foo.js".into()))
|
|
);
|
|
assert_eq!(
|
|
locate_sourcemap_reference(input)
|
|
.unwrap()
|
|
.unwrap()
|
|
.get_url(),
|
|
"foo.js"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_no_ref() {
|
|
let input: &[_] = b"foo();\nbar();\n// whatever";
|
|
assert_eq!(locate_sourcemap_reference(input).unwrap(), None);
|
|
}
|
|
|
|
#[test]
|
|
fn test_detect_basic_sourcemap() {
|
|
let input: &[_] = br#"{
|
|
"version": 3,
|
|
"sources": ["coolstuff.js"],
|
|
"names": ["x","alert"],
|
|
"mappings": "AAAA,GAAIA,GAAI,EACR,IAAIA,GAAK,EAAG,CACVC,MAAM"
|
|
}"#;
|
|
assert!(is_sourcemap_slice(input));
|
|
}
|
|
|
|
#[test]
|
|
fn test_detect_bad_sourcemap() {
|
|
let input: &[_] = br#"{
|
|
"sources": ["coolstuff.js"],
|
|
"names": ["x","alert"]
|
|
}"#;
|
|
assert!(!is_sourcemap_slice(input));
|
|
}
|
|
|
|
#[test]
|
|
fn test_detect_basic_sourcemap_with_junk_header() {
|
|
let input: &[_] = br#")]}garbage\n
|
|
{
|
|
"version": 3,
|
|
"sources": ["coolstuff.js"],
|
|
"names": ["x","alert"],
|
|
"mappings": "AAAA,GAAIA,GAAI,EACR,IAAIA,GAAK,EAAG,CACVC,MAAM"
|
|
}"#;
|
|
assert!(is_sourcemap_slice(input));
|
|
}
|