swc/tests/error_msg.rs
강동윤 2211a9908a
fix(swc): Fix various bugs (#1550)
swc:
 - Improve error message for invalid configs. (#1532)

swc_common:
 - Handle input source map correctly. (#1404)

swc_ecma_parser:
 - Fix parsing of generics type declarations when tsx is enabled. (#1526)

swc_ecma_transforms_compat:
 - Allow using carriage return. (#1549)
2021-04-08 12:55:02 +00:00

41 lines
1.1 KiB
Rust

use std::{path::Path, sync::Arc};
use swc::{config::Options, Compiler};
use testing::{NormalizedOutput, Tester};
fn file(f: &str) -> NormalizedOutput {
Tester::new()
.print_errors(|cm, handler| -> Result<NormalizedOutput, _> {
let c = Compiler::new(cm.clone(), Arc::new(handler));
let fm = cm.load_file(Path::new(f)).expect("failed to load file");
let s = c.process_js_file(
fm,
&Options {
swcrc: true,
is_module: true,
..Default::default()
},
);
if let Err(e) = s {
return Ok(format!("{:?}", e).into());
}
panic!("invalid swcrc should abort build, but got {:?}", s);
})
.unwrap()
}
#[test]
fn swcrc_simple() {
let f = file("tests/swcrc_errors/simple/foo.js");
println!("{}", f);
}
#[test]
fn issue_1532() {
let f = file("tests/swcrc_errors/issue-1532/index.js");
println!("{}", f);
assert!(f.contains("unknown variant `esnext`"))
}