2021-02-26 12:21:42 +03:00
|
|
|
use std::path::PathBuf;
|
|
|
|
use swc_common::pass::Repeat;
|
|
|
|
use swc_ecma_parser::EsConfig;
|
|
|
|
use swc_ecma_parser::Syntax;
|
|
|
|
use swc_ecma_transforms_optimization::simplify::dce::dce;
|
2021-05-13 18:11:27 +03:00
|
|
|
use swc_ecma_transforms_optimization::simplify::expr_simplifier;
|
2021-02-26 12:21:42 +03:00
|
|
|
use swc_ecma_transforms_testing::test_fixture;
|
|
|
|
|
2021-07-29 08:18:21 +03:00
|
|
|
#[testing::fixture("tests/dce/**/input.js")]
|
2021-02-26 12:21:42 +03:00
|
|
|
fn dce_single_pass(input: PathBuf) {
|
|
|
|
let output = input.with_file_name("output.js");
|
|
|
|
|
|
|
|
test_fixture(
|
|
|
|
Syntax::Es(EsConfig {
|
2021-05-30 13:52:51 +03:00
|
|
|
decorators: true,
|
2021-02-26 12:21:42 +03:00
|
|
|
dynamic_import: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
&|_| dce(Default::default()),
|
|
|
|
&input,
|
|
|
|
&output,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-29 08:18:21 +03:00
|
|
|
#[testing::fixture("tests/dce/**/input.js")]
|
2021-02-26 12:21:42 +03:00
|
|
|
fn dce_repeated(input: PathBuf) {
|
|
|
|
let output = input.with_file_name("output.full.js");
|
|
|
|
|
|
|
|
test_fixture(
|
|
|
|
Syntax::Es(EsConfig {
|
2021-05-30 13:52:51 +03:00
|
|
|
decorators: true,
|
2021-02-26 12:21:42 +03:00
|
|
|
dynamic_import: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
&|_| Repeat::new(dce(Default::default())),
|
|
|
|
&input,
|
|
|
|
&output,
|
|
|
|
);
|
|
|
|
}
|
2021-05-13 18:11:27 +03:00
|
|
|
|
2021-07-29 08:18:21 +03:00
|
|
|
#[testing::fixture("tests/expr-simplifier/**/input.js")]
|
2021-05-13 18:11:27 +03:00
|
|
|
fn expr(input: PathBuf) {
|
|
|
|
let output = input.with_file_name("output.js");
|
|
|
|
|
|
|
|
test_fixture(
|
|
|
|
Syntax::Es(EsConfig {
|
|
|
|
dynamic_import: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
2021-07-22 10:33:00 +03:00
|
|
|
&|_| Repeat::new(expr_simplifier()),
|
2021-05-13 18:11:27 +03:00
|
|
|
&input,
|
|
|
|
&output,
|
|
|
|
);
|
|
|
|
}
|