Skip to content

Commit 64f80d4

Browse files
committed
remove duplicate code
1 parent 2a69112 commit 64f80d4

1 file changed

Lines changed: 4 additions & 76 deletions

File tree

tests/common/mod.rs

Lines changed: 4 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,81 +7,7 @@ use orchestrion_js::*;
77
use std::io::prelude::*;
88
use std::path::PathBuf;
99
use std::process::Command;
10-
use std::sync::Arc;
11-
use swc::{
12-
config::{IsModule, SourceMapsConfig},
13-
try_with_handler, Compiler, HandlerOpts, PrintArgs,
14-
};
15-
use swc_core::common::{comments::Comments, errors::ColorConfig, FileName, FilePathMapping};
16-
use swc_core::ecma::ast::EsVersion;
17-
use swc_ecma_parser::{EsSyntax, Syntax};
18-
use swc_ecma_visit::VisitMutWith;
19-
20-
fn print_result(original: &str, modified: &str) {
21-
println!(
22-
"\n - == === Original === == - \n{}\n\n\n - == === Modified === == - \n{}\n\n",
23-
original, modified
24-
);
25-
}
26-
27-
fn transpile(
28-
contents: &str,
29-
is_module: IsModule,
30-
instrumentation: &mut InstrumentationVisitor,
31-
) -> String {
32-
let compiler = Compiler::new(Arc::new(swc_core::common::SourceMap::new(
33-
FilePathMapping::empty(),
34-
)));
35-
try_with_handler(
36-
compiler.cm.clone(),
37-
HandlerOpts {
38-
color: ColorConfig::Never,
39-
skip_filename: false,
40-
},
41-
|handler| {
42-
let source_file = compiler.cm.new_source_file(
43-
Arc::new(FileName::Real(PathBuf::from("index.mjs"))),
44-
contents.to_string(),
45-
);
46-
47-
let program = compiler
48-
.parse_js(
49-
source_file.to_owned(),
50-
handler,
51-
EsVersion::latest(),
52-
Syntax::Es(EsSyntax {
53-
explicit_resource_management: true,
54-
import_attributes: true,
55-
decorators: true,
56-
..Default::default()
57-
}),
58-
is_module,
59-
Some(&compiler.comments() as &dyn Comments),
60-
)
61-
.map(|mut program| {
62-
program.visit_mut_with(instrumentation);
63-
program
64-
})
65-
.unwrap();
66-
let result = compiler
67-
.print(
68-
&program,
69-
PrintArgs {
70-
source_file_name: None,
71-
source_map: SourceMapsConfig::Bool(false),
72-
comments: None,
73-
emit_source_map_columns: false,
74-
..Default::default()
75-
},
76-
)
77-
.unwrap();
78-
79-
print_result(contents, &result.code);
80-
Ok(result.code)
81-
},
82-
)
83-
.unwrap()
84-
}
10+
use swc::config::IsModule;
8511

8612
static TEST_MODULE_NAME: &str = "undici";
8713
static TEST_MODULE_PATH: &str = "index.mjs";
@@ -101,7 +27,9 @@ pub fn transpile_and_test(test_file: &str, mjs: bool, config: Config) {
10127
let mut contents = String::new();
10228
file.read_to_string(&mut contents).unwrap();
10329

104-
let result = transpile(&contents, IsModule::Bool(mjs), &mut instrumentations);
30+
let result = instrumentations
31+
.transform(&contents, IsModule::Bool(mjs))
32+
.unwrap();
10533

10634
let instrumented_file = test_dir.join(format!("instrumented.{}", extension));
10735
let mut file = std::fs::File::create(&instrumented_file).unwrap();

0 commit comments

Comments
 (0)