Skip to content

Commit a6d8330

Browse files
committed
add new() to all transpilers
1 parent b7a0078 commit a6d8330

File tree

5 files changed

+42
-30
lines changed

5 files changed

+42
-30
lines changed

rust/cubetranspilers/src/check_dup_prop_transpiler.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ pub struct CheckDupPropTransformVisitor {
1717
}
1818

1919
impl CheckDupPropTransformVisitor {
20-
fn emit_error(&self, span: Span, message: &str) {
20+
pub fn new(source_map: Option<PluginSourceMapProxy>) -> Self {
21+
CheckDupPropTransformVisitor { source_map }
22+
}
23+
24+
fn emit_error(&mut self, span: Span, message: &str) {
2125
HANDLER.with(|handler| {
2226
handler
2327
.struct_span_err(span, &self.format_msg(span, message))

rust/cubetranspilers/src/cube_prop_ctx_transpiler.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ pub struct CubePropTransformVisitor {
7373
}
7474

7575
impl CubePropTransformVisitor {
76+
pub fn new(
77+
cube_names: HashSet<String>,
78+
cube_symbols: HashMap<String, HashMap<String, bool>>,
79+
context_symbols: HashMap<String, String>,
80+
source_map: Option<PluginSourceMapProxy>,
81+
) -> Self {
82+
CubePropTransformVisitor {
83+
source_map,
84+
cube_names,
85+
cube_symbols,
86+
context_symbols,
87+
}
88+
}
89+
7690
fn emit_error(&self, span: Span, message: &str) {
7791
HANDLER.with(|handler| {
7892
handler

rust/cubetranspilers/src/import_export_transpiler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pub struct ImportExportTransformVisitor {
1515
}
1616

1717
impl ImportExportTransformVisitor {
18+
pub fn new(source_map: Option<PluginSourceMapProxy>) -> Self {
19+
ImportExportTransformVisitor { source_map }
20+
}
21+
1822
fn emit_error(&self, span: Span, message: &str) {
1923
HANDLER.with(|handler| {
2024
handler

rust/cubetranspilers/src/lib.rs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub enum Transpilers {
3030
ValidationTranspiler,
3131
}
3232

33-
#[derive(Deserialize, Clone, Debug)]
33+
#[derive(Deserialize, Clone, Debug, Default)]
3434
#[serde(rename_all = "camelCase")]
3535
pub struct TransformConfig {
3636
pub file_name: String,
@@ -40,18 +40,6 @@ pub struct TransformConfig {
4040
pub context_symbols: HashMap<String, String>,
4141
}
4242

43-
impl Default for TransformConfig {
44-
fn default() -> Self {
45-
Self {
46-
file_name: String::new(),
47-
transpilers: Vec::new(),
48-
cube_names: HashSet::new(),
49-
cube_symbols: HashMap::new(),
50-
context_symbols: HashMap::new(),
51-
}
52-
}
53-
}
54-
5543
#[derive(Serialize, Clone, Debug)]
5644
#[serde(rename_all = "camelCase")]
5745
pub struct TransformResult {
@@ -84,7 +72,9 @@ pub fn run_transpilers(
8472
};
8573

8674
let sm_cell = OnceCell::new();
87-
sm_cell.set(sf.clone()).map_err(|_err| anyhow!("Failed to init OnceCell with source file"))?;
75+
sm_cell
76+
.set(sf.clone())
77+
.map_err(|_err| anyhow!("Failed to init OnceCell with source file"))?;
8878

8979
let plugin_source_map = PluginSourceMapProxy {
9080
source_file: sm_cell,
@@ -95,30 +85,26 @@ pub fn run_transpilers(
9585
.into_iter()
9686
.for_each(|transpiler| match transpiler {
9787
Transpilers::CubeCheckDuplicatePropTranspiler => {
98-
let mut visitor = CheckDupPropTransformVisitor {
99-
source_map: Some(plugin_source_map.clone()),
100-
};
88+
let mut visitor =
89+
CheckDupPropTransformVisitor::new(Some(plugin_source_map.clone()));
10190
program.visit_mut_with(&mut visitor);
10291
}
10392
Transpilers::CubePropContextTranspiler => {
104-
let mut visitor = CubePropTransformVisitor {
105-
cube_names: transform_config.cube_names.clone(),
106-
cube_symbols: transform_config.cube_symbols.clone(),
107-
context_symbols: transform_config.context_symbols.clone(),
108-
source_map: Some(plugin_source_map.clone()),
109-
};
93+
let mut visitor = CubePropTransformVisitor::new(
94+
transform_config.cube_names.clone(),
95+
transform_config.cube_symbols.clone(),
96+
transform_config.context_symbols.clone(),
97+
Some(plugin_source_map.clone()),
98+
);
11099
program.visit_mut_with(&mut visitor);
111100
}
112101
Transpilers::ImportExportTranspiler => {
113-
let mut visitor = ImportExportTransformVisitor {
114-
source_map: Some(plugin_source_map.clone()),
115-
};
102+
let mut visitor =
103+
ImportExportTransformVisitor::new(Some(plugin_source_map.clone()));
116104
program.visit_mut_with(&mut visitor);
117105
}
118106
Transpilers::ValidationTranspiler => {
119-
let mut visitor = ValidationTransformVisitor {
120-
source_map: Some(plugin_source_map.clone()),
121-
};
107+
let mut visitor = ValidationTransformVisitor::new(Some(plugin_source_map.clone()));
122108
program.visit_mut_with(&mut visitor);
123109
}
124110
});

rust/cubetranspilers/src/validation_transpiler.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ pub struct ValidationTransformVisitor {
1616
}
1717

1818
impl ValidationTransformVisitor {
19+
pub fn new(source_map: Option<PluginSourceMapProxy>) -> Self {
20+
ValidationTransformVisitor { source_map }
21+
}
22+
1923
fn emit_warn(&self, span: Span, message: &str) {
2024
HANDLER.with(|handler| {
2125
handler

0 commit comments

Comments
 (0)