2020-02-17 09:56:41 +03:00
|
|
|
use rayon::prelude::*;
|
2020-11-23 20:54:18 +03:00
|
|
|
use std::{
|
|
|
|
fs::create_dir_all,
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
sync::Arc,
|
|
|
|
};
|
2020-02-17 09:56:41 +03:00
|
|
|
use swc::{
|
2020-07-27 14:21:52 +03:00
|
|
|
config::{Config, JscConfig, ModuleConfig, Options, SourceMapsConfig, TransformConfig},
|
2020-02-17 09:56:41 +03:00
|
|
|
Compiler,
|
|
|
|
};
|
2020-07-31 12:49:07 +03:00
|
|
|
use swc_ecma_parser::{Syntax, TsConfig};
|
2019-11-26 04:08:48 +03:00
|
|
|
use testing::{NormalizedOutput, StdErr, Tester};
|
|
|
|
use walkdir::WalkDir;
|
|
|
|
|
|
|
|
fn file(f: &str) -> Result<NormalizedOutput, StdErr> {
|
2020-05-19 14:24:00 +03:00
|
|
|
file_with_opt(
|
|
|
|
f,
|
|
|
|
Options {
|
|
|
|
swcrc: true,
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn file_with_opt(f: &str, options: Options) -> Result<NormalizedOutput, StdErr> {
|
2019-11-26 04:08:48 +03:00
|
|
|
Tester::new().print_errors(|cm, handler| {
|
2020-06-13 17:09:45 +03:00
|
|
|
let c = Compiler::new(cm.clone(), Arc::new(handler));
|
2019-11-26 04:08:48 +03:00
|
|
|
|
|
|
|
let fm = cm.load_file(Path::new(f)).expect("failed to load file");
|
|
|
|
let s = c.process_js_file(
|
|
|
|
fm,
|
2019-11-29 17:46:06 +03:00
|
|
|
&Options {
|
2019-12-11 09:07:21 +03:00
|
|
|
is_module: true,
|
2020-05-19 14:24:00 +03:00
|
|
|
..options
|
2019-11-26 04:08:48 +03:00
|
|
|
},
|
|
|
|
);
|
2019-12-28 05:25:54 +03:00
|
|
|
|
2019-11-26 04:08:48 +03:00
|
|
|
match s {
|
2019-12-28 05:25:54 +03:00
|
|
|
Ok(v) => {
|
|
|
|
if c.handler.has_errors() {
|
|
|
|
Err(())
|
|
|
|
} else {
|
|
|
|
Ok(v.code.into())
|
|
|
|
}
|
|
|
|
}
|
2020-07-27 14:21:52 +03:00
|
|
|
Err(err) => panic!("Error: {:?}", err),
|
2019-11-26 04:08:48 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
fn project(dir: &str) {
|
|
|
|
Tester::new()
|
|
|
|
.print_errors(|cm, handler| {
|
2020-06-13 17:09:45 +03:00
|
|
|
let c = Compiler::new(cm.clone(), Arc::new(handler));
|
2019-11-26 04:08:48 +03:00
|
|
|
|
|
|
|
for entry in WalkDir::new(dir) {
|
|
|
|
let entry = entry.unwrap();
|
|
|
|
if entry.metadata().unwrap().is_dir() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
println!("File: {}", entry.path().to_string_lossy());
|
|
|
|
|
|
|
|
if !entry.file_name().to_string_lossy().ends_with(".ts")
|
|
|
|
&& !entry.file_name().to_string_lossy().ends_with(".js")
|
|
|
|
&& !entry.file_name().to_string_lossy().ends_with(".tsx")
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let fm = cm.load_file(entry.path()).expect("failed to load file");
|
2021-01-18 17:00:53 +03:00
|
|
|
|
|
|
|
if c.config_for_file(
|
|
|
|
&Options {
|
|
|
|
swcrc: true,
|
|
|
|
is_module: true,
|
|
|
|
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
&fm.name,
|
|
|
|
)
|
|
|
|
.expect("failed to read config")
|
|
|
|
.is_none()
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-12-11 17:28:35 +03:00
|
|
|
match c.process_js_file(
|
2019-11-26 04:08:48 +03:00
|
|
|
fm,
|
2019-11-29 17:46:06 +03:00
|
|
|
&Options {
|
2019-11-26 04:08:48 +03:00
|
|
|
swcrc: true,
|
2019-12-11 09:07:21 +03:00
|
|
|
is_module: true,
|
|
|
|
|
2019-11-26 04:08:48 +03:00
|
|
|
..Default::default()
|
|
|
|
},
|
2019-12-11 17:28:35 +03:00
|
|
|
) {
|
|
|
|
Ok(..) => {}
|
2020-03-27 08:40:01 +03:00
|
|
|
Err(ref err) if format!("{:?}", err).contains("not matched") => {}
|
|
|
|
Err(err) => panic!("Error: {:?}", err),
|
2019-12-11 17:28:35 +03:00
|
|
|
}
|
2019-11-26 04:08:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.map(|_| ())
|
2019-12-11 17:28:35 +03:00
|
|
|
.expect("failed");
|
2019-11-26 04:08:48 +03:00
|
|
|
}
|
|
|
|
|
2020-02-17 09:56:41 +03:00
|
|
|
fn par_project(dir: &str) {
|
|
|
|
Tester::new()
|
|
|
|
.print_errors(|cm, handler| {
|
2020-06-13 17:09:45 +03:00
|
|
|
let c = Compiler::new(cm.clone(), Arc::new(handler));
|
2020-02-17 09:56:41 +03:00
|
|
|
|
|
|
|
let entries = WalkDir::new(dir)
|
|
|
|
.into_iter()
|
|
|
|
.map(|entry| entry.unwrap())
|
|
|
|
.filter(|e| {
|
|
|
|
if e.metadata().unwrap().is_dir() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if !e.file_name().to_string_lossy().ends_with(".ts")
|
|
|
|
&& !e.file_name().to_string_lossy().ends_with(".js")
|
|
|
|
&& !e.file_name().to_string_lossy().ends_with(".tsx")
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
entries.into_par_iter().for_each(|entry| {
|
|
|
|
let fm = cm.load_file(entry.path()).expect(
|
|
|
|
"failed to load
|
|
|
|
file",
|
|
|
|
);
|
|
|
|
let _ = c.process_js_file(
|
|
|
|
fm,
|
|
|
|
&Options {
|
|
|
|
swcrc: true,
|
|
|
|
is_module: true,
|
|
|
|
source_maps: Some(SourceMapsConfig::Bool(true)),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
if c.handler.has_errors() {
|
|
|
|
Err(())
|
|
|
|
} else {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.map(|_| ())
|
|
|
|
.expect("");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn angular_core() {
|
|
|
|
par_project("integration-tests/angular/packages/core/src");
|
|
|
|
}
|
2019-12-11 17:28:35 +03:00
|
|
|
|
2019-11-29 17:46:06 +03:00
|
|
|
//#[test]
|
|
|
|
//fn rxjs() {
|
2020-02-17 09:56:41 +03:00
|
|
|
// par_project("integration-tests/rxjs/repo/src");
|
2019-11-29 17:46:06 +03:00
|
|
|
//}
|
|
|
|
//
|
|
|
|
//#[test]
|
|
|
|
//fn webpack() {
|
2020-02-17 09:56:41 +03:00
|
|
|
// par_project("integration-tests/webpack/repo/lib");
|
2019-11-29 17:46:06 +03:00
|
|
|
//}
|
2019-11-26 04:08:48 +03:00
|
|
|
|
|
|
|
/// should respect modules config in .swcrc
|
|
|
|
#[test]
|
|
|
|
fn issue_225() {
|
|
|
|
let s = file("tests/projects/issue-225/input.js").unwrap();
|
|
|
|
println!("{}", s);
|
|
|
|
|
|
|
|
assert!(s.contains("function _interopRequireDefault"));
|
2020-07-28 15:56:19 +03:00
|
|
|
assert!(s.contains("var _foo = _interopRequireDefault(require(\"foo\"))"));
|
2019-11-26 04:08:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// should handle exportNamespaceFrom configured by .swcrc
|
|
|
|
#[test]
|
|
|
|
fn issue_226() {
|
|
|
|
let s = file("tests/projects/issue-226/input.js").unwrap();
|
|
|
|
println!("{}", s);
|
|
|
|
|
|
|
|
assert!(s.contains("import * as _Foo from 'bar';"));
|
|
|
|
assert!(s.contains("export { _Foo as Foo }"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// should handle react correctly
|
|
|
|
#[test]
|
|
|
|
fn issue_351() {
|
|
|
|
let s = file("tests/projects/issue-351/input.js").unwrap();
|
|
|
|
println!("{}", s);
|
|
|
|
|
2020-07-28 15:56:19 +03:00
|
|
|
assert!(s.contains(".default.createElement(\"div\", null);"));
|
2019-11-26 04:08:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// should handle cjs imports
|
|
|
|
#[test]
|
|
|
|
fn issue_389() {
|
|
|
|
let s = file("tests/projects/issue-389/input.js").unwrap();
|
|
|
|
println!("{}", s);
|
|
|
|
|
|
|
|
assert!(s.contains(".default.bar = true"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// should handle comments in arrow expression
|
|
|
|
#[test]
|
|
|
|
fn issue_406() {
|
|
|
|
let s = file("tests/projects/issue-406/input.js").unwrap();
|
|
|
|
println!("{}", s);
|
|
|
|
|
|
|
|
assert!(s.contains("return true"));
|
|
|
|
}
|
|
|
|
|
2019-12-01 11:32:44 +03:00
|
|
|
#[test]
|
|
|
|
fn issue_409_1() {
|
|
|
|
let s = file("tests/projects/issue-409-1/input.js").unwrap();
|
|
|
|
println!("{}", s);
|
|
|
|
|
|
|
|
assert!(s.contains("JSON.parse"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_409_2() {
|
|
|
|
let s = file("tests/projects/issue-409-2/input.js").unwrap();
|
|
|
|
println!("{}", s);
|
|
|
|
|
|
|
|
assert!(!s.contains("JSON.parse"));
|
|
|
|
}
|
|
|
|
|
2019-11-26 04:08:48 +03:00
|
|
|
/// should handle multiple entries in swcrc
|
|
|
|
#[test]
|
|
|
|
fn issue_414() {
|
|
|
|
let s1 = file("tests/projects/issue-414/a.js").unwrap();
|
|
|
|
println!("{}", s1);
|
2020-07-28 15:56:19 +03:00
|
|
|
assert!(s1.contains("require(\"foo\")"));
|
2019-11-26 04:08:48 +03:00
|
|
|
|
|
|
|
let s2 = file("tests/projects/issue-414/b.ts").unwrap();
|
|
|
|
println!("{}", s2);
|
2020-03-02 14:49:08 +03:00
|
|
|
assert!(s2.contains("define("));
|
|
|
|
assert!(s2.contains("function(_bar) {"));
|
2019-11-26 04:08:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/// should handle comments in return statement
|
|
|
|
#[test]
|
|
|
|
fn issue_415() {
|
|
|
|
let s = file("tests/projects/issue-415/input.js").unwrap();
|
|
|
|
|
|
|
|
assert!(s.replace(" ", "").contains("return(/*#__PURE__*/"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_466_1() {
|
|
|
|
project("tests/projects/issue-466-1");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_466_2() {
|
|
|
|
project("tests/projects/issue-466-2");
|
|
|
|
}
|
2019-12-09 15:02:51 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_467() {
|
|
|
|
project("tests/projects/issue-467/");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_468() {
|
|
|
|
file("tests/projects/issue-468/input.ts").expect("failed to parse typescript");
|
|
|
|
}
|
2019-12-24 11:01:32 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_528() {
|
|
|
|
let f = file("tests/projects/issue-528/input.js")
|
|
|
|
.unwrap()
|
|
|
|
.replace(" ", "");
|
|
|
|
let f = f.trim();
|
|
|
|
|
|
|
|
println!("{}", f);
|
|
|
|
assert_eq!(
|
|
|
|
f,
|
|
|
|
"\
|
|
|
|
//bar
|
|
|
|
[
|
|
|
|
//foo
|
|
|
|
a,
|
|
|
|
//bar
|
2020-11-08 04:59:36 +03:00
|
|
|
(//baz
|
|
|
|
b)
|
2019-12-24 11:01:32 +03:00
|
|
|
];"
|
|
|
|
);
|
|
|
|
}
|
2019-12-28 05:25:54 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn env_entry_chrome_49() {
|
|
|
|
let f = file("tests/env/entry/chrome-49/input.js")
|
|
|
|
.unwrap()
|
|
|
|
.replace(" ", "");
|
|
|
|
let f = f.trim();
|
|
|
|
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert_eq!(f.lines().count(), 76);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn env_entry_chrome_71() {
|
|
|
|
let f = file("tests/env/entry/chrome-71/input.js")
|
|
|
|
.unwrap()
|
|
|
|
.replace(" ", "");
|
|
|
|
let f = f.trim();
|
|
|
|
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert_eq!(f.lines().count(), 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn env_query_chrome_71() {
|
|
|
|
let f = file("tests/env/query/chrome-71/input.js")
|
|
|
|
.unwrap()
|
|
|
|
.replace(" ", "");
|
|
|
|
let f = f.trim();
|
|
|
|
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert_eq!(f.lines().count(), 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn project_env() {
|
|
|
|
project("tests/projects/env/");
|
|
|
|
}
|
2019-12-28 16:02:58 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_532() {
|
|
|
|
let f = file("tests/projects/issue-532-block/input.js")
|
|
|
|
.unwrap()
|
|
|
|
.replace(" ", "");
|
|
|
|
let f = f.trim();
|
|
|
|
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
f,
|
|
|
|
"\
|
2020-09-11 09:09:35 +03:00
|
|
|
/*pre:1*/test();
|
|
|
|
test(123/*post:3*/);
|
|
|
|
test(/*pre:4*/123);
|
|
|
|
test(/*pre:5*/123/*post:6*/);
|
|
|
|
test(/*pre:7*/123,/*pre:8*/456);
|
|
|
|
test(123/*post:9*/,456/*post:10*/);"
|
2019-12-28 16:02:58 +03:00
|
|
|
)
|
|
|
|
}
|
2020-01-23 17:23:24 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_602() {
|
|
|
|
let f = file("tests/projects/issue-602/input.js").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(!f.contains("undefined1"));
|
|
|
|
}
|
2020-01-24 08:54:52 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_604_1() {
|
|
|
|
let f = file("tests/projects/issue-604-1/input.js").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(f.contains("_loop(i)"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_605() {
|
|
|
|
let f = file("tests/projects/issue-605/input.js").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(f.contains("Object.keys(_c)"));
|
|
|
|
}
|
2020-02-07 08:33:26 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn await_expr() {
|
|
|
|
let f = file("tests/projects/await-expression/input.js").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(f.contains("await"));
|
|
|
|
assert!(f.contains("test"));
|
|
|
|
}
|
2020-02-08 04:49:00 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn await_expr_2() {
|
|
|
|
let f = file("tests/projects/await-expression-2/input.js").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(f.contains("await"));
|
|
|
|
assert!(f.contains("test"));
|
|
|
|
}
|
2020-02-12 18:07:45 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_config() {
|
|
|
|
project("tests/projects/issue-655")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_658() {
|
|
|
|
project("tests/projects/issue-658")
|
|
|
|
}
|
2020-05-09 06:22:45 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_763() {
|
|
|
|
let f = file("tests/projects/issue-763/input.js").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(f.contains("_consts.RESOURCE_WEBSITE"));
|
|
|
|
assert!(f.contains("_consts.RESOURCE_FACEBOOK"));
|
|
|
|
assert!(f.contains("_consts.RESOURCE_INSTAGRAM"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_763_2() {
|
|
|
|
let f = file("tests/projects/issue-763-2/input.js").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(f.contains("_consts.RESOURCE_WEBSITE"));
|
|
|
|
assert!(f.contains("_consts.RESOURCE_FACEBOOK"));
|
|
|
|
assert!(f.contains("_consts.RESOURCE_INSTAGRAM"));
|
|
|
|
}
|
2020-05-18 17:25:41 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_779_1() {
|
|
|
|
let f = file("tests/projects/issue-779-1/input.js").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
2020-07-28 15:56:19 +03:00
|
|
|
assert!(f.contains("require(\"core-js/modules/es.array-buffer.constructor\");"))
|
2020-05-18 17:25:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_779_2() {
|
|
|
|
let f = file("tests/projects/issue-779-2/input.js").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
2020-07-28 15:56:19 +03:00
|
|
|
assert!(f.contains("require(\"core-js\");"));
|
2020-05-18 17:25:41 +03:00
|
|
|
}
|
2020-05-19 14:24:00 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_783() {
|
|
|
|
let f = file("tests/projects/issue-783/input.js").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
2020-07-28 15:56:19 +03:00
|
|
|
assert!(!f.contains("require(\"core-js\");"));
|
|
|
|
assert!(f.contains("require(\"core-js/modules/es.array-buffer.constructor\");"))
|
2020-05-19 14:24:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_783_core_js_2() {
|
|
|
|
let f = file_with_opt(
|
|
|
|
"tests/projects/issue-783/input.js",
|
|
|
|
Options {
|
|
|
|
swcrc: false,
|
|
|
|
config: Some(Config {
|
2020-07-31 12:49:07 +03:00
|
|
|
env: Some(swc_ecma_preset_env::Config {
|
2020-05-19 14:24:00 +03:00
|
|
|
core_js: Some("2".parse().unwrap()),
|
2020-07-31 12:49:07 +03:00
|
|
|
mode: Some(swc_ecma_preset_env::Mode::Entry),
|
2020-05-19 14:24:00 +03:00
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
!f.contains("'core-js'"),
|
|
|
|
"import of `core-js` should be transformed"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_783_core_js_3() {
|
|
|
|
let f = file_with_opt(
|
|
|
|
"tests/projects/issue-783/input.js",
|
|
|
|
Options {
|
|
|
|
swcrc: false,
|
|
|
|
config: Some(Config {
|
2020-07-31 12:49:07 +03:00
|
|
|
env: Some(swc_ecma_preset_env::Config {
|
|
|
|
mode: Some(swc_ecma_preset_env::Mode::Entry),
|
2020-05-19 14:24:00 +03:00
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
!f.contains("'core-js'"),
|
|
|
|
"import of `core-js` should be transformed"
|
|
|
|
);
|
|
|
|
}
|
2020-05-28 06:00:34 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_801() {
|
|
|
|
let f = file("tests/projects/issue-801/input.ts").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(!f.contains("function delete"));
|
|
|
|
}
|
2020-07-02 07:10:44 +03:00
|
|
|
|
|
|
|
#[test]
|
2020-09-22 10:39:00 +03:00
|
|
|
#[ignore]
|
2020-07-02 07:10:44 +03:00
|
|
|
fn concurrency() {
|
|
|
|
par_project("tests/deno-unit");
|
|
|
|
}
|
2020-07-27 14:21:52 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_879() {
|
|
|
|
let f = file_with_opt(
|
|
|
|
"tests/projects/issue-879/input.ts",
|
|
|
|
Options {
|
|
|
|
is_module: true,
|
|
|
|
config: Some(Config {
|
|
|
|
env: Some(Default::default()),
|
|
|
|
module: Some(ModuleConfig::CommonJs(Default::default())),
|
|
|
|
jsc: JscConfig {
|
|
|
|
syntax: Some(Syntax::Typescript(TsConfig {
|
|
|
|
tsx: true,
|
|
|
|
decorators: true,
|
|
|
|
..Default::default()
|
|
|
|
})),
|
|
|
|
transform: Some(TransformConfig {
|
|
|
|
legacy_decorator: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(f.find("function X").is_some(), "swc should compile class");
|
|
|
|
assert_eq!(
|
|
|
|
f.find("function X"),
|
|
|
|
f.rfind("function X"),
|
|
|
|
"swc should not emit `function X` twice"
|
|
|
|
);
|
|
|
|
}
|
2020-07-27 16:58:42 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_895() {
|
|
|
|
let f = file("tests/projects/issue-895/input.ts").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(f.contains("_url ="));
|
|
|
|
assert!(f.contains("_url.queryString"));
|
|
|
|
let s = f.replace("_url =", "").replace("_url.queryString", "");
|
|
|
|
|
|
|
|
assert!(!s.contains("_url."));
|
|
|
|
assert!(!s.contains("_url,"));
|
|
|
|
}
|
2020-09-09 09:16:44 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_1052() {
|
|
|
|
let f = file("tests/projects/issue-1052/input.ts").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(!f.contains("_new"))
|
|
|
|
}
|
2020-11-08 04:59:36 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_1203() {
|
|
|
|
let f = file("tests/projects/issue-1203/input.js").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert!(!f.contains("return //"))
|
|
|
|
}
|
2020-11-20 20:04:29 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn codegen_1() {
|
|
|
|
let f = file("tests/projects/codegen-1/input.js").unwrap();
|
|
|
|
println!("{}", f);
|
|
|
|
|
|
|
|
assert_eq!(f.to_string(), "\"\\\"\";\n");
|
|
|
|
}
|
2020-11-23 20:54:18 +03:00
|
|
|
|
|
|
|
#[testing::fixture("fixture/**/input/")]
|
|
|
|
fn tests(dir: PathBuf) {
|
|
|
|
let output = dir.parent().unwrap().join("output");
|
|
|
|
let _ = create_dir_all(&output);
|
|
|
|
|
|
|
|
Tester::new()
|
|
|
|
.print_errors(|cm, handler| {
|
|
|
|
let c = Compiler::new(cm.clone(), Arc::new(handler));
|
|
|
|
|
|
|
|
for entry in WalkDir::new(&dir) {
|
|
|
|
let entry = entry.unwrap();
|
|
|
|
if entry.metadata().unwrap().is_dir() {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
println!("File: {}", entry.path().to_string_lossy());
|
|
|
|
|
|
|
|
if !entry.file_name().to_string_lossy().ends_with(".ts")
|
|
|
|
&& !entry.file_name().to_string_lossy().ends_with(".js")
|
|
|
|
&& !entry.file_name().to_string_lossy().ends_with(".tsx")
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let fm = cm.load_file(entry.path()).expect("failed to load file");
|
|
|
|
match c.process_js_file(
|
|
|
|
fm,
|
|
|
|
&Options {
|
|
|
|
swcrc: true,
|
|
|
|
is_module: true,
|
|
|
|
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
Ok(v) => {
|
|
|
|
NormalizedOutput::from(v.code)
|
|
|
|
.compare_to_file(output.join(entry.file_name()))
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
Err(ref err) if format!("{:?}", err).contains("not matched") => {}
|
|
|
|
Err(err) => panic!("Error: {:?}", err),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.map(|_| ())
|
|
|
|
.expect("failed");
|
|
|
|
}
|